2011-06-28 85 views
1

我正在用Zend Server在Zend MVC中创建一个Hello World项目。一些路由是错误的。我创建项目通过zend_tool zf.sh创建项目,因此它创建的所有目录本身,我修改为indexController的尝试像下面的一些行动,和所有其他文件提醒一样..zend框架简单的动作问题

<?php 

class IndexController extends Zend_Controller_Action 
{ 

    public function init() 
    { 
     /* Initialize action controller here */ 
    $this->_helper->viewRenderer->setNoRender(); 
    } 

    public function indexAction() 
    { 
     // action body 
    $this->getResponse()->appendBody('hello from about Action'); 
    } 

    public function aboutAction() 
    { 
    $this->getResponse()->appendBody('hello from about Action'); 
     // action body 
    } 


} 


当我输入“http://localhost/index.php”,它显示来自indexAction()的正确信息;
当我输入“http:// localhost/index”,它显示页面没有找到
当我输入“http://localhost/index.php/about”,
它显示“消息:无效的控制器指定(约)“ 请求参数:

阵列( '控制器'=> '约',
'动作'=> '索引', '模块'=> '默认', )

我期望控制器是索引和行动是关于..我怎么能修复它...

我有这在我的apache配置。我想我可能有这个配置错误,但我不知道在哪里。

<VirtualHost *:80> 
#DocumentRoot "/usr/local/zend/apache2/htdocs" 
DocumentRoot /home/testuser/projects/helloworldproject/public 
<Directory "/home/testuser/projects/helloworldproject/public/"> 
    SetEnv APPLICATION_ENV "development" 
    Order allow,deny 
    Allow from All 
</Directory> 

感谢您的时间。

回答

0

我想这正是错误信息说的,这就是你需要一个控制器about,你没有。在url http://localhost/index.php/about,about将是一个完全独立的控制器,你需要建立。

+0

但我预计服务器解释指数控制器的左右作用。 – Nissan911

+0

@ Nissan911我明白你为什么会这么想。但是,Zend正在以上述格式寻找一个“about”控制器。 – Nic

1
  • localhost/index.php应该去index控制器,默认情况下(index, index)index行动。
  • localhost/index也应该去(index,index)
  • index.php/about我希望去(about,index),即about控制器和index行动,但我可能是错的(我没有测试这一点)。
  • 如果你想去(index,about)你会去localhost/index/about

您似乎是正确定义的有关行动public function aboutAction,这样应能正常工作。 如果您希望能够转到localhost/about或localhost/about/index,您需要像为IndexController所做的那样定义一个像class AboutController extends Zend_Controller_Action这样的控制器。

- 编辑 - 此外,请确保您的.htaccess着眼于最低是这样的:

DirectoryIndex index.php 

RewriteEngine On 

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

正如我所说的。找不到localhost/index - >页面。和localhost/index/about服务器解释为关于控制器,这完全不是我的意思.. – Nissan911

+0

@ Nissan911是你的.htaccess正确配置? – Nic

+0

你正在使用哪个Web服务器?如果Apache,你有你的.htaccess正确配置? – ashurexm