Code snippets for symfony 1.x


Snippets by user Rich Sage

Generating Symfony URLs in other projects and subdirectories

Integrating Phorum into a Symfony project at, I wanted to use my existing Symfony URLs in my Phorum templates:

// This path should be the path to your config/ProjectConfiguration.class.php file
// in your Symfony project
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', sfConfig::get("sf_environment"), true);
$instance = sfContext::createInstance($configuration);
$routing = $instance->getRouting();
// Our URLs may have a prefix (eg /forum/index.php).  Remove this
$routingOptions = $routing->getOptions();
$urlPrefix = (array_key_exists("prefix", $routingOptions["context"]) ? $routingOptions["context"]["prefix"] : "");
$myURL = $routing->generate("default", array("module" => "foo", "action" => "bar"));
$myURL = str_replace($urlPrefix, "", $myURL);
by Rich Sage on 2010-05-06, tagged phorum  route  url 

Retrieving action variables in a component

Used in a component action, the following code can be used to get the variables set in a module action that has used the component in its view:

$actionStack = $this->context->getActionStack();
$variables = $actionStack->getFirstEntry()->getActionInstance()->getVarHolder();

then you can use

$foo = $variables->get("foo");

to retrieve a variable. Note that the above is for the most recent action only.

by Rich Sage on 2009-10-01, tagged action  component  variables