开发者

cakephp populate HABTM select box in EDIT form

开发者 https://www.devze.com 2023-02-27 07:34 出处:网络
I am using cakephp\'s form for an HABTM relationship between User and Event.There is a join table events_users.The form works well for the Add form, but not for the edit form.The code is:

I am using cakephp's form for an HABTM relationship between User and Event. There is a join table events_users. The form works well for the Add form, but not for the edit form. The code is:

Controller:

$this->data = $this->Event->findById($id);

Form field:

$this->Form->input('User');

开发者_高级运维What I get is a blank, input box. Unlike the select box in the Add form. Any ideas what I'm doing wrong or how to populate a select box with the right Users selected for the input on the edit form?


I figured it out. I modified the controller to use this instead:

$this->data=$this->Event->findById($id);
$users = $this->Event->User->find('list');
$this->set(compact('data','users'));

It works.

0

精彩评论

暂无评论...
验证码 换一张
取 消