1

我正在使用 Zend Server 在 Zend MVC 中创建一个 hello world 项目。一些路由是错误的。我通过 zend_tool zf.sh 创建项目创建项目,因此它自己创建所有目录,我修改为 indexController 以尝试以下操作,所有其他文件都提醒相同..

<?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”时
找不到页面 ,它显示“消息:指定的控制器无效(关于)”请求参数:

数组( 'controller' => 'about',
'action' => 'index', 'module' => 'default', )

我希望控制器是索引和动作是关于..我该如何解决它......

我在我的 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>

谢谢你的时间。

4

2 回答 2

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

您似乎已经正确定义了 about 操作public function aboutAction,因此它应该可以正常工作。如果您希望能够访问 localhost/about 或 localhost/about/index,您将需要定义一个 about 控制器,就像class AboutController extends Zend_Controller_Action您为IndexController.

-- 编辑 -- 另外,请确保您的 .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]
于 2011-06-28T02:50:06.717 回答
0

我认为这正是错误消息所说的,即您需要一个about您没有的控制器。在 urlhttp://localhost/index.php/about中,about将是您需要建立的完全独立的控制器。

于 2011-06-28T02:46:03.083 回答