测试CRUD生成的Create表单时收到以下错误。有谁熟悉这个问题?提前谢谢。
未定义索引:contactindivs
07 $this->render('view', array(
08 'model' => $this->loadModel($id, 'Companylocation'),
09 ));
10 }
11
12 public function actionCreate() {
13 $model = new Companylocation;
14
15
16 if (isset($_POST['Companylocation'])) {
17 $model->setAttributes($_POST['Companylocation']);
18 $relatedData = array(
19 'contactindivs' => $_POST['Companylocation']['contactindivs'] === '' ? null : $_POST['Companylocation']['contactindivs'],
20 );
21
22 if ($model->saveWithRelated($relatedData)) {
23 if (Yii::app()->getRequest()->getIsAjaxRequest())
24 Yii::app()->end();
25 else
26 $this->redirect(array('view', 'id' => $model->CompanyLocationID));
27 }
28 }
29
30 $this->render('create', array( 'model' => $model));
31 }
答案 0 :(得分:1)
第19行说明,如果contactindivs ===''使它为null。将其更改为此并且不应该给出错误。
$contactindivs = isset($_POST['Companylocation']['contactindivs']) ? $_POST['Companylocation']['contactindivs'] : '';
$relatedData = array(
'contactindivs' => $contactindivs,);
问题是您收到警告是因为您检查了“公司位置”,而不是['公司位置'] [' contactindivs']。那应该解决它。