[英]How to in view pass array data to controller with model(in one atribute) Yii
It is my view in Yii framework. 这是我在Yii框架中的观点。 i wanna pass from here array data to controller with only one model attribute or just array without model.
我想从这里将数组数据传递给只有一个模型属性的控制器,或者只是没有模型的数组。 how to do it?
怎么做?
<?php $i = 1; foreach ($images as $image):
CHtml::activeLabel($model, 'remove', array('for'=>'rm_'.$image))
CHtml::activeCheckBox($model,'remove',array('name'=>'Obyavlenie[remove]', 'id'=>'rm_'.$image)) // remove is array(attribute) to pass
CHtml::link($image, 'name', array()),$image);
in model 在模型中
class Obyavlenie extends CActiveRecord
{
public $remove;// should get array from view
尝试这个
<?php echo CHtml::activeCheckBox($model,'remove',array('name'=>'Obyavlenie[remove]['.$image.']', 'id'=>'rm_'.$image)) ?>
Use CheckBoxList
for multiple values. 对多个值使用
CheckBoxList
。
In view: 鉴于:
// 1. Set data list
$list = array();
foreach ($images as $image):
$list[ $image ] = CHtml::link($image,'#'); // Change [ $image ] unique identificator to determine image you need
endforeach;
// 2. Output checkboxes
CHtml::activeCheckBoxList($model,'remove',$list,array(
'template' => '{input} {label}'
));
In action: 实际上:
$model = new Obyavlenie('removeImages');
if ( isset( $_POST['Obyavlenie'] ) ) {
$model->attributes = $_POST['Obyavlenie']
}
In model: 在模型中:
class Obyavlenie extends CActiveRecord {
public $remove;
public function rules(){
return array(
// ...
array( 'remove', 'type', 'type' => 'array', 'on' => 'removeImages' )
);
}
// other model's methods
PS Obyavlenie -> Advert PS Obyavlenie->广告
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.