0

在测试 CRUD 生成的创建表单时,我收到以下错误。有谁熟悉这个问题?提前谢谢。

未定义索引: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     }
4

1 回答 1

1

第 19 行说明如果 contactindivs === '' 使其为空。将其更改为此,它不应该给出错误。

$contactindivs = isset($_POST['Companylocation']['contactindivs']) ? $_POST['Companylocation']['contactindivs'] : '';
$relatedData = array(
     'contactindivs' => $contactindivs,);

问题是您收到警告是因为您检查了“Companylocation”,但没有检查 ['Companylocation']['contactindivs']。那应该解决它。

于 2013-06-11T20:23:35.423 回答