Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - Html->link - why use controller=> and action=> instead of just controller/action

Why this:

echo $this->Html->link('Add a User', array('controller'=>'users', 'action'=>'add'));

Instead of just this:

echo $this->Html->link('Add a User', 'users/add');
like image 618
Dave Avatar asked Feb 25 '23 16:02

Dave


1 Answers

The second example will always generate a url of 'users/add'. The first provides the potential of using reverse routing to form a bespoke url, as defined by the rules in your routes.php file.

In practice I often find that there's no difference between the first and the second style. However, if you later decide to make changes to your routes, you might find that doing things the first time saves time in the long run, so you don't have to go back and change the path for every link...

like image 180
thesunneversets Avatar answered Apr 26 '23 00:04

thesunneversets