[英]Yii CArrayDataProvider Keyfield As Button Id In CGridView
My issue is two-fold. 我的问题有两个方面。 First, I'm unable to correctly set the keyField for CArrayDataProvider, all I'm getting back is a string instead of a value.
首先,我无法正确设置CArrayDataProvider的keyField,我得到的只是字符串而不是值。 Second, I'm trying to use the keyField inside of CArrayDataProvider to set an id on the button in each row inside of CGridView.
其次,我试图使用CArrayDataProvider内部的keyField在CGridView内部每一行的按钮上设置一个id。 The reason I want to do this is so that I can pass the id value onward to an ajax function (if there's a better way to do this in Yii, I'm all ears).
我想这样做的原因是,我可以将id值向前传递给ajax函数(如果在Yii中有更好的方法可以做到这一点,那么我真是耳目一新)。 Any help would be much appreciated, thanks in advance!
任何帮助将不胜感激,在此先感谢!
I also posted this question once on Yii's forums. 我也曾在Yii的论坛上发布过这个问题。 I normally wouldn't repost, but I have had a hard time getting answers there, as opposed to stack overflow, you guys are the best!
我通常不会转发,但是我很难在那儿得到答案,与堆栈溢出相反,你们是最好的! Here's the link to my original post if anyone is interested.
如果有人感兴趣, 这是我原始帖子的链接 。
Here is how I'm building the array that I'm using as my RAW data: 这是我如何构建用作RAW数据的数组:
foreach ($items as $item) {
$tableRow = array("id"=>$item["Id"], "Organization"=>$item["Organization"], "Roles"=>$item["Roles"]);
$return_items[] = $tableRow;
}
Here is the CArrayDataProvider setup I'm using. 这是我正在使用的CArrayDataProvider设置。 I noticed that 'keyField' is not being given the id value, just the string 'id':
我注意到'keyField'没有被赋予id值,只是字符串'id':
$dataProvider=new CArrayDataProvider($return_items, array(
'keyField'=>'id',
'sort'=>array(
'attributes'=>array(
'Organization',
'Roles',
),
),
'pagination'=>array(
'pageSize'=>10,
),
));
Lastly, here is the CGridView I'm trying to setup in the view. 最后,这是我尝试在视图中设置的CGridView。 All that appears on the button is the id tag, but no value:
按钮上显示的只是id标记,但没有值:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$authItems,
'columns'=>array(
'Organization',
'Roles',
array('name'=>'',
'type'=>'raw',
'htmlOptions'=>array('id'=>'id'),
'value'=>'CHtml::button("Edit Roles", array("data-toggle"=>"modal", "data-target"=>"#roles-modal"))'),
),
));
Try passing it via CHtml::button which you have already applied. 尝试通过已应用的CHtml :: button传递它。 Eg
例如
'value'=>'CHtml::button("Edit Roles", array(
"id"=>$data["id"],
"data-toggle"=>"modal",
"data-target"=>"#roles-modal"
))'),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.