为什么Symfony重定向不刷新页面?

时间:2018-10-28 08:10:11

标签: php symfony symfony-1.2

我正尝试在用户单击注销时注销用户,但是当我单击注销时,页面无法正确刷新,即注销后显示了显示登录表单,但显示了用于登录的数据用户。因此,当我进行强制刷新时,它可以工作,但是当我仅单击注销按钮并使用如下的$this->redirect('@recipes_index');函数时,它就无法工作。

路线:

recipes_logout:
  url:   meals-recipes/logout
  param: {module: recipes, action: logout}

用户控制器:

public function RecipeUserLogin($user) {
        $this->setAuthenticated(true);
        $this->addCredential('recipe_user');
        $this->setAttribute('id', $user['id'], 'recipe_user');
        $this->setAttribute('email', $user['email'], 'ketogenic_recipe_user');
        $this->setAttribute('name', $user['first_name'] . " " . $user['last_name'], 'recipe_user');
    }

    public function RecipeUserLogout() {
        $this->getAttributeHolder()->removeNamespace('recipe_user');
        $this->removeCredential('recipe_user');
    }

点击时调用的功能:

public function executeLogout(sfWebRequest $request) {
      $this->getUser()->RecipeUserLogout();
      $this->redirect('@recipes_index');
  }

查看:

<?php if(!$sf_user->hasCredential('recipe_user')): ?>
                <form class="form-inline" method="post" >
                    <?php echo $form['email']->render(array('class' => 'form-control mb-sm', 'placeholder' => 'Email', 'value' => base64_decode($sf_request->getParameter('user')) )); ?>
                    <?php echo $form['password']->render(array('class' => 'form-control mb-sm','type' => 'password', 'placeholder' =>'Password')); ?>
                    <input type="submit" class="btn btn-primary mb-sm " name="submit" value="Sign in">
                    <?php echo $form['password']->renderError() ?>
                    <?php echo $form['email']->renderError() ?>
                    <?php echo $form->renderHiddenFields(); ?>
                    <br>
                    <a href="<?php echo url_for('@recipes_forgot_pass'); ?>">Reset Password</a>
                </form>
            <?php else: ?>
            <div> You are logged in as <?php echo $sf_user->getAttribute('name', null, 'recipe_user'); ?>.</div>
            <a href="<?php echo url_for('@recipes_logout'); ?>">Logout</a>
            <br>
            <?php endif; ?>

0 个答案:

没有答案