我已经阅读了很多信息,但我不明白如何从 checkBoxList 获取演员 ID。我有表演员,连接,电影与多对多。一切都差不多好了,在$_POST
点击保存表单后,有:
array (size=3)
'Film' =>
array (size=2)
'name' => string 'bvb' (length=3)
'about' => string 'fdgg' (length=4)
'Actors' =>
array (size=1)
'id' =>
array (size=1)
0 => string '2' (length=1)
'yt0' => string 'Create' (length=6)
所以我试图把我$_POST['Actors']['id']
的连接表,但没有任何反应:
protected function afterSave(){
$actors=$this->ActorsArray;
parent::afterSave();
$postCat = new Connect();
$postCat->id_film = $this->id;
if (isset($_POST['Actors'])){
$postCat->id_actor = $_POST['Actors']}
$postCat->save();
}
这是来自电影控制器:
public function actionCreate()
{
$model=new Film;
$model1=new Actors();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Film']))
{
$model->attributes=$_POST['Film'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,'model1'=>$model1,
));
}