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

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

Ruby on Rails

routes.rb

map.my_route '/my-route', :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 path is better, because I can make changes to the "url", and I don't need the code changes of all views.

+3
source share
1 answer

Use the version of the array in the view. CakePHP performs reverse routing to determine which string reference to use, i.e. '/ My-route', from the array of controllers / actions / params in the array.

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

Also check it out from Marc Gandolfo

+3

Source: https://habr.com/ru/post/1738745/


All Articles