cakephp populate HABTM select box in EDIT form
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.
精彩评论