Showing posts with label CButtonColumn. Show all posts
Showing posts with label CButtonColumn. Show all posts

Saturday, June 1, 2013

YII CGridView with custom action button


<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    "itemsCssClass" => "table_design_1",
    "htmlOptions" => array(
        "class" => "div_contact_admin_grid_view"
    ),
    "ajaxUpdate" => false,
    'columns'=>array(
        array(
            'name'=>'family_name', 
            'header'=>'First name',
            'type' => 'raw',
            'value' => 'CHtml::link($data->family_name,$data->id)'
        ),
        array(
            'name'=>'given_name', 
            'header'=>'Last name',
            'type' => 'raw',
            'value' => 'CHtml::link($data->given_name,$data->id)'
        ),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{delete_contact}{view}{update}',
            'buttons'=>array (
                'delete_contact' => array (
                    'label'=>'Delete this contact',
                    'imageUrl'=>Yii::app()->request->baseUrl.'/images/delete.png',
                    'url'=>'Yii::app()->createUrl("contact/delete", array("id"=>$data->id))',
                    'visible' => '1',
                    "options" => array(
                        "class" => "delete_contact"
                    )
                )
            ),
            'viewButtonUrl'=>'Yii::app()->request->getBaseUrl(true)."/contact/view/".$data["id"]',
            'updateButtonUrl'=>'Yii::app()->request->getBaseUrl(true)."/contact/update/".$data["id"]',
            "htmlOptions" => array(
                'style'=>'width: 60px;',
                'class' => 'action_class'
            )
        )
    )
)); ?>

Thursday, May 23, 2013

YII TbButtonColumn Urlencode() Expects Parameter 1 To Be String, Array Given

I can not understand anything the global did not, I put to show the button in CGridView when table has multiple primary key.

array(
                'class'=>'bootstrap.widgets.TbButtonColumn',
                'htmlOptions'=>array('style'=>'width: 50px'),
            ),
it gives me:
urlencode() expects parameter 1 to be string, array given
C:\xampp\htdocs\contactwebspace\framework\web\CUrlManager.php(758)
746 
747         if($manager->matchValue && $this->matchValue===null || $this->matchValue)
748         {
749             foreach($this->params as $key=>$value)
750             {
751                 if(!preg_match('/\A'.$value.'\z/u'.$case,$params[$key]))
752                     return false;
753             }
754         }
755 
756         foreach($this->params as $key=>$value)
757         {
758             $tr["<$key>"]=urlencode($params[$key]);
759             unset($params[$key]);
760         }
761 
762         $suffix=$this->urlSuffix===null ? $manager->urlSuffix : $this->urlSuffix;
763 
764         $url=strtr($this->template,$tr);
765 
766         if($this->hasHostInfo)
767         {
768             $hostInfo=Yii::app()->getRequest()->getHostInfo();
769             if(stripos($url,$hostInfo)===0)
770                 $url=substr($url,strlen($hostInfo));
It seems that my yii does not like composite primary keys in models.
I use it with GridView, CButtonColumn and an url issue update like :

array('class'=>'CButtonColumn', 
'viewButtonUrl'=>'Yii::app()->controller->createUrl("view",$data->primaryKey)', 
'updateButtonUrl'=>'Yii::app()->controller->createUrl("update",$data->primaryKey)', 
'deleteButtonUrl'=>'Yii::app()->controller->createUrl("delete",$data->primaryKey)',
)

Or you can use as following:
array('class'=>'CButtonColumn', 
'viewButtonUrl'=>'Yii::app()->request->getBaseUrl(true)."/contact/view/".$data["id"]', 
'updateButtonUrl'=>'Yii::app()->request->getBaseUrl(true)."/contact/update/".$data["id"]', 
'deleteButtonUrl'=>'Yii::app()->request->getBaseUrl(true)."/contact/delete/".$data["id"]',
)