views:

773

answers:

4

I'm trying to render a partial in a Symfony task and having no luck. I found docs in 1.1 that say to just call get_partial() but apparently that's no longer readily available in 1.4. I tried loading the helper manually with sfLoader::getHelpers('Partial'); but I get "Class sfLoader not found". Any help would be greatly appreciated.

For reference what I'm trying to do is generate an HTML file called 'header.html' from my global header partial used in all of my layouts for inclusion in a third-party forum I'm integrating (Simple Machines/SMF).

A: 

sfLoader was deprecated in symfony 1.2 - I think you need to look over the 1.4 API and the upgrade help from whichever version you're familiar with, as these are going to be resources you'll need to refer to a lot.

The trick to solving your problem is to load the helper with the loadHelpers() method provided by the sfApplicationConfiguration class - your task should hook this method in its configure() method. I've not done it before myself, mind...

Raise
The only configuration I have access to in the execute method is a ProjectConfiguration instance in `$this->configuration`, any idea how to get an instance of sfApplicationConfiguration? I found that you can do $this->getContext()->getConfiguration()->loadHelpers(...) in an action but I don't have access to that configuration or context. If I try to get the current context using `sfContext::getInstance` I get "The 'default' context does not exist". To create a new context using `sfContext::createInstance()` I need an ApplicationConfiguration to pass in :-/.
Cryo
A: 

you can access the current configuration with

$this->configuration

You can also define application command option in taskClass::configure() method (if you have used the symfony generate:task to generate the task class you should have frontend as default application option). Optionally you can pass an application using --application=appName from cli when calling your task.

ftassi
A: 

Don't forget to add an application name in your task's options. Look for this line:

new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED,'The application name', 'frontend')

Now $this->configuration returns the sfApplicationConfiguration that you need.

Guillaume Flandre
A: 

This will do the trick:

//load the Partial helper to be able to use get_partial()
$contextInstance = sfContext::createInstance($this->configuration);
$contextInstance->getConfiguration()->loadHelpers('Partial');
Thiuda