2012-09-11 33 views
2

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

我正在运行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://本地主机/”在浏览器中的“应用程序/视图/脚本/指数/”目录中的文件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的文件;

/的意见/脚本/测试/ 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://本地主机/测试/” 我得到一个404错误,指出无法找到请求的网址。我已阅读的所有Zend Framework文档以及无数其他资源均声明此方法应正确呈现。

我必须缺少一些东西,但经过详尽的搜索后,无法找到其他人有这个特殊问题。

问候罗安

回答

1

尝试在目录

+0

我appologies是从我的行动和PHTML名玩耍,试图找出问题这个错误中提到的模块。我已将TestController.php中的操作名称更改回indexAction,并将test目录中的文件更改为index.phtml,但“http:// localhost/test”仍然返回404错误 – roanboy56

+0

服务器配置可能有问题?如果我键入“http:// localhost”,index.phtml文件呈现ok,但如果我键入“http:// localhost/index”或“http:// localhost/index/index”,则不会显示。我读过的所有文档都说这应该起作用 – roanboy56

+0

@ user1661725确定尝试在索引控制器中创建一个新动作,然后再说anotherAction(),然后在view/scripts/index/another.phtml中创建视图,看它是否有效。如果它的工作,那么一切似乎没问题,你必须重新检查错字/正确的目录路径等 – codisfy

1

创建测试控制器...或test.phtml一个的indexAction,你可以检查第二URL本地主机/测试正在经历你的index.php。 你可以放一个die()或一些调试语句。

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 

,并删除 '#'。

+0

感谢您的回复。 – roanboy56

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 

干杯

相关问题