什么是正确的命名或我缺少什么来自动运行名为 Model 的两个单词。实际模型属于模型两个词。
确切的例子:旅游属于住宿类型。在数据库中有来自旅游的表tours
和表accommodation_types
外键是tours.accommodation_type_id
下面代码的快照。
ToursController.php
public function add() {
//...
$accommodation_types = $this->Tour->AccommodationType->find('list');
//...
$this->set(compact('accommodation_types', ...));
}
旅游.php
//...
public $belongsTo = array(
//...
'AccommodationType' => array(
'className' => 'AccommodationType',
'foreignKey' => 'accommodation_type_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
//...
);
Tours/add.ctp(在表格内)
echo $this->Form->input('accommodation_type_id', array('label' => 'Accommodation type'));