我有3个表:
project,amenities和project_amenities.
我只添加项目表单,我想添加新的设施,首先添加到设施表,然后添加project_amenities表.
所以我定义了这些关系:
Project hasMany Amenities
Amenity belongsTo Project
我宣布projects_controller:
var $uses = array('Amenity');
这为我的添加操作提供了错误
if (!empty($this->data)){
$this->Project->create();
Run Code Online (Sandbox Code Playgroud)
如
Notice (8): Undefined property: ProjectsController::$Project
[APP\controllers\projects_controller.php, line 60]
Run Code Online (Sandbox Code Playgroud)
编辑 另外,我做不到:
$this->Amenity->create();
$insertData = array('name' => $this->data['Project']['Amenity'][$i]['name']);
$this->Amenity->save($insertData);
Run Code Online (Sandbox Code Playgroud)