2

奇怪,但它是真的。我的过滤器.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();
    }
}
?>

我想要的帽子?while 站点始终需要登录用户 - 或者您只能看到登录页面。当您没有登录或同时退出时,URL 必须保留,并获得登录页面,您应该会看到一个“空”模块(登录部分显示在其他地方)。

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

4

2 回答 2

4

尝试添加

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();
    }
}
?>
于 2013-01-07T10:04:24.057 回答
1

尝试更改->forward(->redirect(

于 2013-01-07T01:34:33.367 回答