Saturday, January 8, 2011

Generating URL from Model or Task

I needed to send emails from a task.


I have tried to load certain helpers but it did not work properly. In my output url was still "/symfony/symfony/".


To make it work I had to define context:
sfContext::createInstance($this->configuration); 
And then I have created a helper in my lib/helper directory (myUrlHelper.class.php), that defines my needs: 
 
class myUrlHelper
{
  public static function url_for($lang, $request, $token)
  {
    $url = 
            sfConfig::get('app_web_address','http://www.give-me-back.com') .
            $lang . '/'.
            $request . '/'.
            $token
            ;

    return $url;
  }
}
 


Then you can call your new url helper like this:
 
myUrlHelper::url_for($reminder->getUser()->getCulture(), 'url_link_request', $item->getToken)); 

No comments:

Post a Comment