The key was to use a filter at the right place. Before "execution" :
too early, actions are not yet executed. After "execution" : too late,
nothing else can be executed after. So we have to replace "execution"
filter.
First, I added a singleton to your class. This way it's easier to use
in actions and in a filter : the access to the title is centralized.
[php]
protected static $instance = null;
/**
* @return sfTitleMaker
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new sfTitleMaker();
}
return self::$instance;
}
[/php]
Then, I made a new filter, extending sfExecutionFilter, and overriding
the executeView() method, using the precedent singleton to set Title.
[php]
class sfTitleMakerExecutionFilter extends sfExecutionFilter
{
protected function executeView($moduleName, $actionName, $viewName,
$viewAttributes)
{
sfContext::getInstance()->getResponse()->setTitle
(sfTitleMaker::getInstance());
parent::executeView($moduleName, $actionName, $viewName,
$viewAttributes);
}
}
[/php]
This way, I just have to call "sfTitleMaker::getInstance()->add
('part')" to add "part" to my title ;)
Example :
[php]
public function executeToto()
{
sfTitleMaker::getInstance()->add('test1');
sfTitleMaker::getInstance()->add('test2');
sfTitleMaker::getInstance()->add('test3');
}
[/php]
Nothing else, and it produces "test1 » test2 » test3".
On 18 mar, 15:45, Tom Haskins-Vaughan
wrote:
> Hi,
>
> I wrote a plugin a little while ago called sfTitleMakerPlugin[1] that
> allows you to compose a 'modular' title and then use it in the tag.
>
> Currently though I have to add a preExecute and postExecute in each
> action to initiate then send the title. I'm sure there must be a way of
> doing it so that this is done automatically, maybe with filters or
> events. Is anyone willing to give me some pointers on this plugin? I did
> try filters but had no success.
>
> Cheers,
>
> Tom
>
> [1]http://trac.symfony-project.org/browser/plugins/sfTitleMakerPlugin
> --
> Tom Haskins-Vaughan
> Temple Street Media: Design and Development for the Web
> t...@templestreetmedia.com |www.templestreetmedia.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---