gpt4 book ai didi

php - 当我在过滤器中使用 forward 时,整个布局被渲染了两次

转载 作者:行者123 更新时间:2023-12-02 22:17:48 25 4
gpt4 key购买 nike

奇怪,但这是真的。我的过滤器.yml:

# You can find more information about this file on the symfony website:
# http://www.symfony-project.org/reference/1_4/en/12-Filters

rendering: ~
security: ~

# insert your own filters here

myFilter:
class: myFilter

cache: ~
execution: ~

和这个过滤器:

<?php
class MyFilter extends sfFilter
{
/**
* @return
*/
public function execute ($filterChain)
{
if ($this->isFirstCall())
{
if NOT LOGGED IN
{
$this->getContext()->getUser()->setFlash ('error', 'login again!');
$this->getContext()->getController()->forward('glbl', 'empty');
}
}

$filterChain->execute();
}
}
?>

hat I want? The while site needs a logged user all the time - or all you can see is the login page. When youre not login, or get logged out in the meantime, the URL must remain, and get the login page, and you should see an "empty" module (the login partial is showed somewhere else).

但是它会渲染整个布局两次。即使是 <html>标签重复。怎么了?

最佳答案

尝试添加

throw new sfStopException();

前进后:

<?php
class MyFilter extends sfFilter
{
/**
* @return
*/
public function execute ($filterChain)
{
if ($this->isFirstCall())
{
if NOT LOGGED IN
{
$this->getContext()->getUser()->setFlash ('error', 'login again!');
$this->getContext()->getController()->forward('glbl', 'empty');
throw new sfStopException();
}
}

$filterChain->execute();
}
}
?>

关于php - 当我在过滤器中使用 forward 时,整个布局被渲染了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14187652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com