当我在过滤器中使用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?

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();
    }
}
?>

Try to change ->forward( to ->redirect(