CakePHP版本为2.x
。我有三个模型
1)room_categories(id,title)
2)room_capacities(id,name)
3)room_details(id,name,room_categories_id,room_capacities_id)
这是我的控制者:
class RoomDetailsController extends AppController {
var $name = "RoomDetails";
function index(){
$this->loadModel('RoomCategory');
$this->loadModel('RoomCapacity');
$roomcategories = $this->RoomCategory->find('list');
$roomcapacities = $this->RoomCapacity->find('list');
$this->set(compact('roomcategories','roomcapacities'));
}
}
在我的视图文件中:
echo $this->Form->input('roomcategory');
echo $this->Form->input('roomcapacity');
下拉是完美的,但当我点击按钮时,它也会向我发送保存信息 但是当我在room_details中看到数据库时,room_categories_id的entery具有零值以及room_capacities_id也是零的相同值
所以,PLZ为我提供了解决方案
答案 0 :(得分:2)
room_details表应该是:
id
name
room_category_id
room_capacity_id
并在视图文件中
echo $this->Form->input('room_category_id');
echo $this->Form->input('room_capacity_id');
并在控制器中
$roomCategories = $this->RoomCategory->find('list');
$roomCapacities = $this->RoomCapacity->find('list');
$this->set(compact('roomCategories','roomCapacities'));