在 Zend Framework 1.8 中使用操作助手

发布于 2024-08-25 21:58:58 字数 1080 浏览 7 评论 0原文

您好,我开始使用 Zend Framework,有一个关于操作助手的问题。我的第一个应用程序是一个简单的身份验证系统(遵循书中的教程)。注册和身份验证似乎工作正常,但重定向却不行。

我有一个客户控制器,其中包含以下内容:

class CustomerController extends Zend_Controller_Action 
{

// some code here......

public function authenticateAction()
{
    $request = $this->getRequest();
    if (!$request->isPost()) {
        return $this->_helper->redirector('login');
    }

    // Validate
    $form = $this->_forms['login'];
    if (!$form->isValid($request->getPost())) {
        return $this->render('login');
    }

    if (false === $this->_authService->authenticate($form->getValues())) {
        $form->setDescription('Login failed, please try again.');
        return $this->render('login');
    }

    return $this->_helper->redirector('index');
}

身份验证网址为 http://localhost/customer/authenticate这似乎工作正常,但它没有重定向。身份验证后,我得到一个空白页面,看起来像是它带我到索引并且就坐在那里。我尝试使用“/index”代替,但这也没有帮助。我需要做一些特殊的事情才能使重定向器帮助程序正常工作吗?我有一个行为相同的注销操作。

Hi am starting off with Zend Framework and have a question about action helpers. My first application is a simple authentication system (following a tutorial from a book). The registration and authentication seems to work fine but the redirect doesn't.

I have a customer controller that has this among others:

class CustomerController extends Zend_Controller_Action 
{

// some code here......

public function authenticateAction()
{
    $request = $this->getRequest();
    if (!$request->isPost()) {
        return $this->_helper->redirector('login');
    }

    // Validate
    $form = $this->_forms['login'];
    if (!$form->isValid($request->getPost())) {
        return $this->render('login');
    }

    if (false === $this->_authService->authenticate($form->getValues())) {
        $form->setDescription('Login failed, please try again.');
        return $this->render('login');
    }

    return $this->_helper->redirector('index');
}

the authenticate url is http://localhost/customer/authenticate and this seems to work fine but it does not redirect. After authentication I get a blank page which looks like its taking me to the index and just sits there. I tried using '/index' instead but that did not help either. Do I need to do anything special to make the redirector helper work? I have a logout action which behaves the same.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所谓喜欢 2024-09-01 21:58:58

您应该

 $this->_helper->redirector('index');

调用返回

You should call

 $this->_helper->redirector('index');

without the return.

雅心素梦 2024-09-01 21:58:58

我发现我的设置可能有问题。上面的代码是完美的,可以在另一台计算机上运行。

I found out there may be a problem with my setup. The code above is perfect, works on another computer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文