<bdo id='Up1Jy'></bdo><ul id='Up1Jy'></ul>

      1. <tfoot id='Up1Jy'></tfoot>

        <i id='Up1Jy'><tr id='Up1Jy'><dt id='Up1Jy'><q id='Up1Jy'><span id='Up1Jy'><b id='Up1Jy'><form id='Up1Jy'><ins id='Up1Jy'></ins><ul id='Up1Jy'></ul><sub id='Up1Jy'></sub></form><legend id='Up1Jy'></legend><bdo id='Up1Jy'><pre id='Up1Jy'><center id='Up1Jy'></center></pre></bdo></b><th id='Up1Jy'></th></span></q></dt></tr></i><div id='Up1Jy'><tfoot id='Up1Jy'></tfoot><dl id='Up1Jy'><fieldset id='Up1Jy'></fieldset></dl></div>

        <legend id='Up1Jy'><style id='Up1Jy'><dir id='Up1Jy'><q id='Up1Jy'></q></dir></style></legend>

        <small id='Up1Jy'></small><noframes id='Up1Jy'>

        Zend Framework 中的简单重写

        时间:2023-10-02

              <small id='1Uovr'></small><noframes id='1Uovr'>

              <tfoot id='1Uovr'></tfoot>
                <i id='1Uovr'><tr id='1Uovr'><dt id='1Uovr'><q id='1Uovr'><span id='1Uovr'><b id='1Uovr'><form id='1Uovr'><ins id='1Uovr'></ins><ul id='1Uovr'></ul><sub id='1Uovr'></sub></form><legend id='1Uovr'></legend><bdo id='1Uovr'><pre id='1Uovr'><center id='1Uovr'></center></pre></bdo></b><th id='1Uovr'></th></span></q></dt></tr></i><div id='1Uovr'><tfoot id='1Uovr'></tfoot><dl id='1Uovr'><fieldset id='1Uovr'></fieldset></dl></div>
                <legend id='1Uovr'><style id='1Uovr'><dir id='1Uovr'><q id='1Uovr'></q></dir></style></legend>
                  <bdo id='1Uovr'></bdo><ul id='1Uovr'></ul>
                    <tbody id='1Uovr'></tbody>
                  本文介绍了Zend Framework 中的简单重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这似乎是一个非常简单的问题,但我只找到了复杂的答案.我有一个需要用户登录的 Zend Framework 应用程序.loginAction()logoutAction()AuthController 中定义.我想允许用户通过 http://www.example.com/login 而不是 登录href="http://www.example.com/auth/login" rel="nofollow">http://www.example.com/auth/login.

                  This seems like a very simple question, but I've only found complicated answers. I've got a Zend Framework application that requires users to login. The loginAction() and logoutAction() are defined in AuthController. I want to allow users to login via http://www.example.com/login rather than http://www.example.com/auth/login.

                  我知道有很多方法可以做到这一点,我考虑过的 3 种方法是:

                  I know there are numerous ways of doing this, the 3 I've considered are:

                  1. .htaccess 重写
                  2. 创建 LoginController 并将 indexAction() 重定向到 auth/login
                  3. 使用 Zend_Controller_Router_Rewrite 定义我自己的路由.

                  如果可能的话,我宁愿将它排除在 #1 之外.#2 很容易理解,虽然它看起来像一个黑客.它还可能会用一堆 5 行控制器"类来混淆代码.我认为 #3 是要走的路,但我不完全了解如何有效地使用它.我试过 使用 Zend_ConfigRewriteRouter 虽然我只定义了登录路由,所以每个链接都变成了/login"(我想我错过了一个默认路由).我在 Bootstrap.php 中做了这个,我不确定那是否正确.

                  I'd rather keep it out of #1 if possible. #2 is easy enough to understand, although it seems like a hack. It also could clutter the code with a bunch of 5-line "Controller" classes. I think #3 is the way to go but I don't fully understand how to use it effectively. I have tried Using Zend_Config with the RewriteRouter although I only defined the login route so every link became '/login' (I think I was missing a default route). I did this in my Bootstrap.php, I'm not sure if that was correct.

                  有没有我遗漏的简单方法?我是否错误地使用了#3?是否有我应该阅读的教程?(我看过 Zend 文档,这很好,但我经常发现自己在问,'这段代码应该放在哪里:在控制器、模型、引导程序中,还是在其他中?')

                  Is there a simple approach I'm missing? Am I using #3 incorrectly? Are there tutorials for this that I should read? (I've looked at the Zend documentation which is good but often I find myself asking, 'Where should this code go: in a controller, model, bootstrap, other?')

                  推荐答案

                  对于一个定义的目的,比如你有一个 命名" 路由,这将是最简单的方法.虽然实现命名路由的方法有很多种,但最简单的方法是将它放在 application.ini 中:

                  for a defined purpose like you have a "named" route would be the simplest way to do it. While there are any number of ways to implement a named route the easiest is to put it in the application.ini:

                      // /application/configs/application.ini
                      resources.router.routes.login.route = /login
                      resources.router.routes.login.defaults.module = default
                      resources.router.routes.login.defaults.controller = auth
                      resources.router.routes.login.defaults.action = login
                  

                  把它放在你的引导程序中并没有错,只是对我来说似乎不太方便.
                  同样这样做应该(不保证)防止默认路由出现任何问题.

                  putting it in your bootstrap is not wrong, it just doesn't seem as convienient to me.
                  Also doing it this way should (no guarantees) prevent any problems with the default routes.

                  当使用 url() 助手调用路由时,重要的是要记住使用命名路由:

                  When calling a route using the url() helper it is important to remember to use either the named route :

                  <?php echo $this->url(array(), 'routeName') ?>
                  

                  或者如果你需要传递普通的 'controller' => , 'action' => :

                  or if you need to pass the normal 'controller' => , 'action' => :

                  <?php echo $this->url(array('controller' => 'index', 'action' => 'index'), 'default') ?>
                  

                  near as I can tell 'default' in this context 表示这将是 Zend/Controller/Router/Route/Module.php 中定义的默认路由

                  near as I can tell 'default' in this context indicates this would be a default route as defined in Zend/Controller/Router/Route/Module.php

                  这篇关于Zend Framework 中的简单重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Zend 表单验证 下一篇:Zend 框架:找不到模型类

                  相关文章

                  最新文章

                  <small id='q9hJm'></small><noframes id='q9hJm'>

                  <i id='q9hJm'><tr id='q9hJm'><dt id='q9hJm'><q id='q9hJm'><span id='q9hJm'><b id='q9hJm'><form id='q9hJm'><ins id='q9hJm'></ins><ul id='q9hJm'></ul><sub id='q9hJm'></sub></form><legend id='q9hJm'></legend><bdo id='q9hJm'><pre id='q9hJm'><center id='q9hJm'></center></pre></bdo></b><th id='q9hJm'></th></span></q></dt></tr></i><div id='q9hJm'><tfoot id='q9hJm'></tfoot><dl id='q9hJm'><fieldset id='q9hJm'></fieldset></dl></div>

                  • <bdo id='q9hJm'></bdo><ul id='q9hJm'></ul>

                  1. <legend id='q9hJm'><style id='q9hJm'><dir id='q9hJm'><q id='q9hJm'></q></dir></style></legend><tfoot id='q9hJm'></tfoot>