Code snippets for symfony 1.x

Navigation

Snippets by user Rich Sage

Generating Symfony URLs in other projects and subdirectories

Integrating Phorum into a Symfony project at http://www.example.com/forum, 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
require_once(dirname(__FILE__).'/../../../config/ProjectConfiguration.class.php');
$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 
(2 comments)

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