【问题标题】:Zend Framework controller load failure puzzleZend Framework 控制器加载失败之谜
【发布时间】:2010-01-16 18:14:16
【问题描述】:

我有一个如下所示的.htaccess 文件:

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

如果我浏览到我正在测试的网站,比如http://www.example.com/,则索引页面会正确加载。

这是一个 Zend Framework 应用程序,因此它应该将事情路由到我的控制器,如果我转到 http://www.example.com/index/indexhttp://www.example.com/index 时它会正确执行,分别指定控制器 + 操作和仅控制器。

如果我执行http://www.example.com/index/test 之类的操作,它也可以工作,我在索引控制器上定义了另一个名为 test 的操作。

但如果我创建一个TestController.php 文件,并尝试转到http://example.com/test/,Apache 将返回:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>404 Not Found</title> 
</head><body> 
<h1>Not Found</h1> 
<p>The requested URL /path/to/website/root/public/index.php was not found on this server.</p> 
<hr> 
<address>Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.4.6 PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch Phusion_Passenger/2.0.3 mod_perl/2.0.3 Perl/v5.8.8 Server at www.example.com Port 80</address> 
</body></html> 

谁能看到我在这里搞砸了什么?

比利3

编辑:我网站的配置类似于:

Alias /MySiteRoot/ "/usr/local/vsites/something/www/"
<Directory /usr/local/vsites/something/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    我通常在 mod_rewrite 不工作时遇到这个问题。

    如果您已启用 mod_rewrite,请在 /etc/apache2/sites-available/yoursite.com 配置文件中检查 AllowOverride 是否设置为 All。

    【讨论】:

    • 如果 mod_rewrite 不工作,为什么http://www.example.com/index/index 工作正常?为什么 /path/to/website/root/public/index.php 存在,尽管 Apache 抱怨相反?
    • 编辑了我的问题 -- AllowOverride All 已列出 :(
    • 有趣——如果我关闭.htaccess 中的MultiViews 选项,那么即使http://www.example.com/index/index 也无法正常工作。我怀疑此时我的 index.php 存在某种权限问题。
    • -rw-rw-r-- 1 颠覆颠覆 754 2010-01-16 22:09 index.php
    • 我没有设置网络服务器。
    【解决方案2】:

    所以如果我没看错的话,路由工作正常,但不是当你只在 url 中指定控制器时。

    所以你有以下内容:

    class TestController extends Zend_Controller_Action
    {
    
        //do you have an index action???
        public function indexAction()
        {
    
        }
    
    }
    

    【讨论】:

    • 是的,我愿意。另请注意,错误消息是由 Apache 生成的——而不是 Zend 框架。
    【解决方案3】:

    事实证明,如果您的站点不是域的根,则必须添加 RewriteBase 指令才能正确格式化。我仍然不知道为什么它事先报告了正确的文件,但它现在似乎可以工作了。

    谢谢,祝你有美好的一天:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 2011-06-23
      • 2012-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多