In a symfony application, I have a list of modules which are built on the doctrine admin generator. Because the app is embedded in another system I need to replace all redirect() calls in the action class (from sfAction.class开发者_StackOverflow社区.php) I can paste this in every module, but is there a central place I could use?
Original redirect (symfony/lib/action/sfACtion.class.php)
public function redirect($url, $statusCode = 302)
{
// compatibility with url_for2() style signature
if (is_object($statusCode) || is_array($statusCode))
{
$url = array_merge(array('sf_route' => $url), is_object($statusCode) ? array('sf_subject' => $statusCode) : $statusCode);
$statusCode = func_num_args() >= 3 ? func_get_arg(2) : 302;
}
$this->getController()->redirect($url, 0, $statusCode);
throw new sfStopException();
}
my change
function redirect($url, $statusCode = 302){
if (is_object($statusCode) || is_array($statusCode)){
$url = array_merge(array('sf_route' => $url), is_object($statusCode) ? array('sf_subject' => $statusCode) : $statusCode);
$statusCode = func_num_args() >= 3 ? func_get_arg(2) : 302;
}
if (is_array($url)){
$use_url = $this->getController()->genUrl($url, true);
}else if (substr($url,0,1) == '@'){
$use_url = $this->getController()->genUrl($url, true);
}else{
$use_url = $url;
}
$url = NZGBCTools::makeUriJoomlaCompatible($use_url);
$this->getController()->redirect($url, 0, $statusCode);
throw new sfStopException();
}
Create a new class, that extends sfActions, and make your action classes extend that. This way you'll have the central place you need.
精彩评论