[symfony-users] Re: sfTitleMakerPlugin

2009-03-18 Thread naholyr

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
-~--~~~~--~~--~--~---



[symfony-users] Re: sfTitleMakerPlugin

2009-03-18 Thread naholyr

I forgot to add the filters.yml, which has to be modified of course

[yml]
rendering: ~
security:  ~

# insert your own filters here

cache: ~
common:~
execution:
  class: sfTitleMakerExecutionFilter   # Filter class
[/yml]

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[symfony-users] Re: sfTitleMakerPlugin

2009-03-19 Thread Tom Haskins-Vaughan

Hi,

I have checked in the changes to the trunk[1] and it seems to be working 
fine. I would like to host it on the symfony website, but before I 
uploaded the package, I wanted to know what the best way was to 
acknowledge the work you have done on it. Should I add you as a developer?

Thanks,

Tom

[1] http://trac.symfony-project.org/browser/plugins/sfTitleMakerPlugin/trunk

naholyr wrote:
> I forgot to add the filters.yml, which has to be modified of course
> 
> [yml]
> rendering: ~
> security:  ~
> 
> # insert your own filters here
> 
> cache: ~
> common:~
> execution:
>   class: sfTitleMakerExecutionFilter   # Filter class
> [/yml]
> 
> > 
> 

-- 
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
-~--~~~~--~~--~--~---