I have been experimenting in CakePHP with links and noticed that sometimes you just pass parameters and sometimes pass them with names prefixed. What is the difference between the two links:
$this->Html->link('Edit', array('controller'=>'users','action'=>'edit', $user['User']['id']));
$this->Html->link('Edit', array('controller'=>'users','action'=>'edit', 'id'=> $user['User']['id']));
The URL they create is largely irrelevant due to the routing capabilities, but in the first example I access the id directly in the controller method like:
public function edit( $id )
but for the named parameter I would have to physically pass it using the router!
Can anyone shed some more light on this? What the difference is and when to use each…
Also worth noting is that in CakePHP 3.0, they have removed named parameters which seems odd because BOTH links would still work… Any thoughts on this?
you dont have to pass named paramteres through the router.
they simply end up in
they will be removed in favor of query string parameters: “?foo=bar&…”
which then will be (as already!) available via
etc
passed will also always be available via
but that you could have all found out reading http://book.cakephp.org/2.0/en/controllers/request-response.html
the main difference between passed onces and named/query is that the latter are more exchangable whereas the passed onces due to their direct access in
are more deeply integrated then and should be used for distinctive information passed.
the named/query ones don’t have a specific order and are more like pagination and other fluent information.
for me passed parameters actually change the site (own canonical link etc) whereas the others don’t do that and “canonical-link” back to the site without any named/query parameters (to avoid duplicate content on pagination etc).