应用程序所有模块的redirect()放在哪里
在 symfony 应用程序中,我有一个基于条令管理生成器构建的模块列表。因为该应用程序嵌入在另一个系统中,所以我需要替换操作类(来自 sfAction.class.php)中的所有重定向()调用,我可以将其粘贴到每个模块中,但是有一个我可以使用的中心位置吗?
原始重定向 (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();
}
我的更改
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();
}
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.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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个扩展 sfActions 的新类,并使您的操作类扩展它。这样您就可以拥有所需的中心位置。
Create a new class, that extends sfActions, and make your action classes extend that. This way you'll have the central place you need.