Thursday, April 7, 2011

Symfony url_for in ACTION

symfony tutorial
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().

generateUrl() Method Signature

string generateUrl('URL_ROUTE',
         array(
        'module'=>'MODULE_NAME',
        'action'=>'ACTION_CALLED',
        'PARAMS'=>'VALUE'
             ),
        $isAbsolute
);
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.

Example

$this->generateUrl('default',
array('module'=>'User','action'=>'EditUser','uid'=>$id))
the out will be something like this...
backend_dev.php/User/EditUser/uid/1130
hope it helps...

0 comments:

Post a Comment

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems