在 zend 框架中使用正确的路由重新渲染页面

发布于 2025-01-02 17:54:47 字数 679 浏览 5 评论 0原文

学习使用 zend 框架,我面临一些小问题。 我使用 Zend_Form 创建一个登录表单,然后在我的控制器中调用我的控制器中的表单

这是我的模块的布局

Module: compte
控制器:compteController
操作:loginAction

在我的 application.ini 中,我为登录路由创建一个资源,如下所示:

resources.router.routes.login.route = /compte/login
resources.router.routes.login.defaults.module = compte
resources.router.routes.login.defaults.controller = compte
resources.router.routes.login.defaults.action = login

然后我像这样调用登录页面 example.com/compte/login 问题是在验证表单时,如果是登录页面再次显示错误,该错误是正确的,但总路径为 example.com/compte/compte/login

我的问题是,如何纠正这个问题,以便当表单无效时,表单在资源管理器中重新显示正确的地址。

预先感谢您的回答

learing to work with zend framework, I am facing some minor problem.
I create a login form with Zend_Form, and then in my Controller I call my form in my controller

Here is the layout of my module

Module: compte
controller: compteController
Action: loginAction

In my application.ini I create a resource for my login route like this:

resources.router.routes.login.route = /compte/login
resources.router.routes.login.defaults.module = compte
resources.router.routes.login.defaults.controller = compte
resources.router.routes.login.defaults.action = login

I then call the login page like this exemple.com/compte/login the problem is that when validating the form, if the is an error the login page display again which is correct but with the total route exemple.com/compte/compte/login.

My question is that how can I correct this problem so that when the form is not valid the form re-display with correct address in the explorer.

Thanks in advance for your answer

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

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

发布评论

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

评论(2

冧九 2025-01-09 17:54:48

表单的操作设置是什么?

也许您需要在视图或控制器中执行 $form->setAction('/compte/login');

What is the form's action set to?

Maybe you need to do $form->setAction('/compte/login'); in the view or controller.

吻泪 2025-01-09 17:54:48

你可以这样做:

if ($form->isValid($_POST) {//This is not real code just for example.

//do some stuff

} else {
    $this->view->errors = $form->getErrors();
    //should go back exactly where you came from
    $this->_redirect($this->getRequest()->getRequestUri());
}

you could do somthing like:

if ($form->isValid($_POST) {//This is not real code just for example.

//do some stuff

} else {
    $this->view->errors = $form->getErrors();
    //should go back exactly where you came from
    $this->_redirect($this->getRequest()->getRequestUri());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文