Zend Framework:当试图通过/controller/action url访问其他视图时,只有索引视图会出现4



我是Zend Framework的新手。

我正在运行Apache2.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显示正常

如果我试图使用url中的控制器和操作名称访问其他视图,我会收到404错误,说在服务器上找不到请求的url。

例如,我有控制器文件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的文件;

/views/scripts/test/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文档和无数其他资源都指出,这种方法应该正确呈现。

我一定错过了什么,但经过彻底的搜索,我找不到其他有这个问题的人。

问候Roan

尝试在测试控制器中创建indexAction。。。或目录中的test.phtml

您可以检查第二个url localhost/test是否正在通过您的index.php吗。您可以为此放置一个die()或一些调试语句。

嗯,试着在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

并删除"#"。

感谢您的回复。

我想我会为其他人发布我的解决方案。。

以下是我在目录标记中的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

干杯

最新更新