dsqpx86002 2013-01-06 22:50
浏览 40
已采纳

当我在过滤器中使用forward时,整个布局呈现两次

Strange, but its true. My filters.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: ~

and this filter:

<?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).

But it then renders the whole layout twice. Even the <html> tag is duplicated. Whats wrong?

  • 写回答

2条回答 默认 最新

  • dtzh131555 2013-01-07 10:04
    关注

    Try adding

    throw new sfStopException();
    

    after the forward:

    <?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();
        }
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题
  • ¥15 pic16F877a单片机的外部触发中断程序仿真失效
  • ¥15 Matlab插值拟合差分微分规划图论
  • ¥15 keil5 target not created
  • ¥15 C/C++数据与算法请教
  • ¥15 怎么找志同道合的伙伴
  • ¥20 如何让程序ab.eXe自已删除干净硬盘里的本文件自己的ab.eXe文件
  • ¥50 爬虫预算充足,跪巨佬
  • ¥15 滑块验证码拖动问题悬赏