开发者

Symfony: using getPartial() in a third party library (in $SFROOT/lib folder)

开发者 https://www.devze.com 2023-03-09 12:15 出处:网络
I am using the events system in Symfony 1.3.8. I am writing logic for the event handlers. As part of my logic, I may need to send email. I therefore need to get the appropriate partial for the email

I am using the events system in Symfony 1.3.8.

I am writing logic for the event handlers. As part of my logic, I may need to send email. I therefore need to get the appropriate partial for the email to be sent.

What is the best way to do this?

I have this so far:

class MyEventHandler
{
    public static function handleFooEvent(sfEve开发者_开发技巧nt $event)
    {
         // I need to get partial here
         // $body = $this->getPartial('somemodule', 'foo', $params);
    }
}

I notice that getPartial() is implemented in sfAction like this:

  public function getPartial($templateName, $vars = null)
  {
    $this->getContext()->getConfiguration()->loadHelpers('Partial');

    $vars = null !== $vars ? $vars : $this->varHolder->getAll();

    return get_partial($templateName, $vars);
  }


To load an helper from anywhere in your application, you can use the following:

sfProjectConfiguration::getActive()->loadHelpers("Partial", "Url", "MyHelper");

Then you can get the needed partial just with:

get_partial('somemodule/somepartial', $params)
0

精彩评论

暂无评论...
验证码 换一张
取 消