Accessing CakePHP named vars and PHP GET vars and difference between the two -
what difference between /action?query=value
, /action/query:value
as latter seems way query strings handled in cakephp , how do either latter or former in cake?
thanks
example of regular php:
...action.php?name=blah&id=7
you can access like:
$name = $_get['name']; $id = $_get['id'];
example named parameters in cakephp:
...action/name:blah/id:7
and can access them this:
$name = $this->params['named']['name']; $id = $this->params['named']['id'];
update: it's no longer recommended use named parameters in cakephp have been removed in cakephp 3.0+
benefits of using named parameters in cakephp:
- full router support (see @deceze comment below explaining this)
- makes easier/cleaner when combining things paginate
- better seo (depending on you're passing)
- you're in cakephp - use cakephp stuff <-- says jokingly
- ...and more?
side note:
you can sent parameters via url/cakephp without using named parameters:
...action/blah/7
these retrieved function vars:
function action($name, $id) {
Comments
Post a Comment