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"]',
)

No comments:

Post a Comment