CakePHP HtmlHelper link() method accepts 2 types of variable as second parameter (the link URL param).
Now I wonder if using array for the param, like
array('controller'=>'users','action'=>'login')
is slower than using string, like '/users/login'. Because Helper won’t have to parse the array, just display the link.
If it is so, then what is the purpose of link() method? For now, I am using HtmlHelper::url() method with a regular <a> to display all of my links, to keep my template clean!
Please correct me 🙂
One reason is reverse routing: For examples, if you route ‘/blah’ to array(‘controller’=>’articles’,’action’=>’index’). When you create the link with array(‘controller’=>’articles’,’action’=>’index’), cake can automatically output ‘/blah’. It may not sound very interesting; but if later on you change the route to ‘/foo’, then the link() method can automatically change the output to ‘/foo’.
Another reason is: using array you can build the url in a programmatic fashion. It’s not just controller and action, you also have prefix, named parameters, your own custom parameters if you create in routes, etc.
For now, I am using HtmlHelper::url() method with a regular <a> to display all of my links, to keep my template clean!Well, you are making it harder on yourself then 🙂