Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "forward"

Forward in filters

The regular use of forward is causing double content rendering and it took me a while to find the proper solution so here it is:

<?php
 
class SiteFilter extends sfFilter
{
 
  public function execute($filterChain)
  {
    $context = $this->getContext();
 
    if($this->isFirstCall()){
      if(true){ // put some condition in here
        $context->getController()->forward('module', 'action');
        throw new sfStopException(); // the solution
      }
    }
 
    $filterChain->execute();
  }
}
 

As you can see sfStopException() is the key.

by rozwell on 2012-06-08, tagged content  double  filter  filters  forward  rendering 

forward wrapper that accepts a routing label

Here is a forward method wrapper that accepts a routing label. Since forward does not do parameters neither does this. Though it would be nice.

public static function fooForward(&$sfa, $route)
  {
    $url = sfContext::getInstance()->getController()->genUrl($route);
    $routing = explode("/", $url, 3);
    switch (count($routing))
    {
      case (3):
        $sfa->forward($routing[1],$routing[2]);
        break;
      case (2):
        $sfa->forward($routing[1], 'index');
        break;
      default:
        error_log(sprintf("Error in fooForward for routing label %s", $route));
        break;
    }
  }

Call it in an action:

  public function handleError()
  {
    fooTools::fooForward($this, '@someLabel');
  }

If there where parameters in the label the $url would have them. Though they can not be used in this case.

by roland cruse on 2006-09-27, tagged action  forward  handleerror  routing 
(3 comments)