开发者

Call named routes in CakePHP as the same way in Ruby on Rails

开发者 https://www.devze.com 2022-12-24 15:50 出处:网络
How can I call a route (in the view) in CakePHP as the same way in Rails? Ruby on Rails routes.rb map.my_route \'/my-rout开发者_如何学JAVAe\', :controller => \'my_controller\', :action => \'i

How can I call a route (in the view) in CakePHP as the same way in Rails?

Ruby on Rails

routes.rb

map.my_route '/my-rout开发者_如何学JAVAe', :controller => 'my_controller', :action => 'index'

view

link_to 'My Route Name', my_route_path

CakePHP

routes.php

Router::connect('/my-route', array('controller' => 'my_controller', 'action' => 'index'));

view

$html->link('My Route Name', '/my-route');

I think the Rails way is better, because I can make changes in the "url" and I don't need changes the code of all views.


Use the array version in the view. CakePHP does reverse routing to determine the string link to use, i.e. '/my-route', from the array of controller / action / params in the array.

$html->link('My Route Name', array('controller' => 'my_controller', 'action' => 'index'));

Also check out this from Mark Gandolfo

0

精彩评论

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