Symfony url_for() method return the URL according to current context, remember url_for method is available only in VIEW part of Symfony MVC, what if one wants to create a HTML in MODEL (although it is not recommended, just in case) and in that HTML there are link which needs to be formatted according to current context, for that there is a method in Symfony generateUrl().
URL_ROUTE is the SEO Friendly URL pattern you defined in config file of module, if not defined use 'default' second is the config array in which we define module name and the action we want to call next is the parameter we want to pass via URL you can pass as many as you want params through it, in the form 'PARAM1'=>'VALUE1','PARAM2'=>'VALUE2',.... and last parameter is $isAbsolute it instruct whether we want relative or absolute URL, default is false it generate relative URL by default.
the out will be something like this...
generateUrl() Method Signature
string generateUrl('URL_ROUTE',
array(
'module'=>'MODULE_NAME',
'action'=>'ACTION_CALLED',
'PARAMS'=>'VALUE'
),
$isAbsolute
);
Example
$this->generateUrl('default',
array('module'=>'User','action'=>'EditUser','uid'=>$id))
array('module'=>'User','action'=>'EditUser','uid'=>$id))
backend_dev.php/User/EditUser/uid/1130
Fuente: http://www.tutorialjinni.com/2011/04/symfony-urlfor-in-action.html
No hay comentarios:
Publicar un comentario