Zend Framework:当尝试通过/ controller / action url访问其他视图时,只有索引视图呈现404错误

时间:2012-09-11 04:15:21

标签: zend-framework frameworks

我是Zend Framework的新手。

我正在运行Apache 2.2,并已将httpd.conf文件中的DocumentRoot设置为使用Zend_Tool创建的公共目录。

在公共目录中,我有一个.htaccess文件;

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

...和index.php文件;

<?php

// Define path to application directory
/*defined('APPLICATION_PATH')
    || */define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

$application->bootstrap()->run();

当我在浏览器中输入“http:// localhost /”时,“application / views / scripts / index /”目录中的文件index.phtml呈现为正常。

如果我尝试使用网址中的控制器和操作名称访问其他视图,则会收到404错误,指出无法在服务器上找到请求的网址。

例如,我有控制器文件TestController.php 与IndexController.php在同一目录中

/ TestController.php /

<?php

class TestController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function testAction()
    {
        // action body
    }


}

我在“application / views / scripts /”中创建了一个包含名为index.phtml的文件的测试目录;

/ 视图/脚本/测试/ index.phtml /

<br /><br />
<div id="view-content">
<p>View script for controller <b>Test</b> and script/action name <b>index</b></p>
</div>

当我尝试通过键入“http:// localhost / test /”来呈现此文件时,出现404错误,指出无法找到请求的URL。我读过的所有Zend Framework文档和无数其他资源都声明这个方法应该正确呈现。

我必须遗漏一些东西,但经过详尽的搜索后找不到其他人遇到这个问题。

关心罗恩

4 个答案:

答案 0 :(得分:1)

尝试在测试控制器中创建一个indexAction ...或者在目录

中创建test.phtml

答案 1 :(得分:1)

你能检查第二个url localhost / test是否通过你的index.php。 你可以为它设置一个die()或一些调试语句。

答案 2 :(得分:0)

嗯尝试在httpd.conf文件中添加它:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot Link to yourSiteFolder exp. C:/AppServ/www/yourSite/public
ServerName youServerName exp. http://mysite.com or you ip http://xxx.xxx.xxx.xxx
 </VirtualHost>

<Directory "Link to yourSiteFolder exp. C:/AppServ/www/yourSite/public">
Options FollowSymLinks
AllowOverride All
</Directory>

找到这个:

#LoadModule rewrite_module modules/mod_rewrite.so

并删除'#'。

答案 3 :(得分:0)

感谢您的回复。

以为我会为别人发布我的解决方案..

以下是我在目录标记中的httpd.conf文件中更新的部分;

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All

我之前没有注释上面提到的模块

LoadModule rewrite_module modules/mod_rewrite.so

干杯