zend框架简单动作问题

发布于 2024-11-17 14:00:26 字数 1416 浏览 3 评论 0原文

我正在使用 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”时,
它显示“消息:指定的控制器无效(关于)” 请求参数:

数组( '控制器' => '关于',
'行动' => '索引', '模块' => '默认', )

我希望控制器是索引,动作是关于..我该如何修复它...

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

感谢您抽出时间。

i am creating a hello world project in Zend MVC with Zend Server. some how the routeing is wrong. I create the project by zend_tool zf.sh create project, so it creates all directory itself, and i modified to indexController to try some actions like below, and all other file reminds the same..

<?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
    }


}

when i enter "http://localhost/index.php", it shows the correct info from indexAction();

when i enter "http://localhost/index", it shows page not found

when i enter "http://localhost/index.php/about",
it shows " Message: Invalid controller specified (about) "
Request Parameters:

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

i expect controller be index and action be about.. how can i fix it...

i have this in my apache config. i think i may have this configured wrong, but i dont know where.

<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>

thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人的夜不怕黑 2024-11-24 14:00:26
  • 默认情况下,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< /code>,这样应该可以正常工作。
如果您希望能够访问 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]
  • localhost/index.php should go to the index controller and the index action by default (index, index).
  • localhost/index should ALSO go to (index,index)
  • index.php/about I would expect goes to (about,index), that is the about controller and index action, but I could be wrong (I didn't test this).
  • If you want to go to (index,about) you would go to localhost/index/about

You appear to have correctly defined the about action public function aboutAction, so that should work properly.
If you want to be able to go to localhost/about or localhost/about/index you will need to define an about controller like class AboutController extends Zend_Controller_Action as you've done for the IndexController.

-- EDIT --
Also, make sure your .htaccess looks at minimum like this:

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]
童话 2024-11-24 14:00:26

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

I think it's exactly the error message is saying, which is that you need a controller for about that you don't have. In the url http://localhost/index.php/about, about would be a completely separate controller that you'd need to establish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文