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)
精彩评论