Hi,
I don't think it's a good idea to add stylesheet at the plugin
initialization. And I'm pretty sure that the response it's not
initialized yet.
You should play with sf core events to add your stylesheet before
rendering with something like that (in your xxxPluginConfiguration
class):
public function configure()
{
$this->dispatcher->connect('context.load_factories', array($this,
'listenToLoadFactories'));
}
public function listenToLoadFactories(sfEvent $event)
{
$event->getSubject()->getResponse()->addStylesheet('my_stylesheet');
}
On Sat, Jan 17, 2009 at 12:53 AM, Jack Bates <[email protected]> wrote:
>
> I am working on a plugin which adds stylesheets to the response based
> on configuration from the database. In my first attempt, I tried
> calling '$response->addStylesheet(...)' in my
> PluginConfiguration::initialize() method, but got this error:
>
> sfException: The "default" context does not exist. in /home/jablko/
> public_html/foo/lib/vendor/symfony/lib/util/sfContext.class.php on
> line 110
> Call Stack
> # Time Memory Function Location
> 1 0.0004 64548 {main}( ) ../foo_dev.php:0
> 2 0.0057 300552 sfProjectConfiguration::getApplicationConfiguration
> ( ) ../foo_dev.php:12
> 3 0.0090 485168 sfApplicationConfiguration->__construct( ) ../
> sfProjectConfiguration.class.php:571
> 4 0.0226 805556 sfApplicationConfiguration->initConfiguration( )
> ../
> sfApplicationConfiguration.class.php:50
> 5 0.0343 1309692 sfApplicationConfiguration->initializePlugins( )
> ../
> sfApplicationConfiguration.class.php:144
> 6 0.0463 1969968 fooPluginConfiguration->initialize( ) ../
> sfApplicationConfiguration.class.php:171
> 7 0.0474 2060108 sfContext::getInstance( ) ../
> fooPluginConfiguration.class.php:28
>
> I got a similar error trying to access the database in my
> PluginConfiguration::initialize() method.
>
> So I guess PluginConfiguration::initialize() is called before the
> context or database connection exist. What is the correct approach to
> adding stylesheets to the response, based on configuration from the
> database?
>
> This is roughly what my PluginConfiguration::initialize() looks like:
>
> $property = PropertyPeer::retrieveByPk('stylesheet');
>
> $response = sfContext::getInstance()->getResponse();
> $response->addStylesheet($property->getValue());
> >
>
--
Noël GUILBERT
http://www.noelguilbert.com/
http://www.sensiolabs.com
http://www.symfony-project.com
Sensio Labs
Tél: +33 1 40 99 80 80
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---