开发者

nested routing in cakephp, associated model

开发者 https://www.devze.com 2023-03-26 10:43 出处:网络
I have two associated models (meetings and departments). A meeting has exactly one department, a department many meetings.

I have two associated models (meetings and departments). A meeting has exactly one department, a department many meetings.

I want to expose this association with a restful URL, such as for instance

myapp/departments/mydepartmentid/meetings/ 
myapp/departments/mydepartmentid/meetings/mymeetingid 
myapp/departments/mydepartmentid/meetings/add

One thing is to configure the routing so that the right actions are called in the meeting c开发者_运维问答ontroller, but I also would like the HTMLhelper to create links that expose the association, e.G the link should be

myapp/departments/mydepartmentid/meetings/mymeetingid

when I link to a meeting.

How can I do this?

thanks

Kurt


a Meeting should belongsTo a Department. If you configure the routes correctly, HtlpHelper should work automatically.

Router::connect('/departments/:dept_id/meetings', array('controller' => 'meetings','action'=>'index'));
Router::connect('/departments/:dept_id/meetings/:action/*', array('controller' => 'meetings'));

You can get to :dept_id somewhere in $this->params['dept_id'] in the controller. For the HtmlHelper use 'dept_id'=>$some_id in the options array.

0

精彩评论

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