【问题标题】:My controllers doesn't work我的控制器不工作
【发布时间】:2013-01-30 22:28:15
【问题描述】:

我在 my.phpcloud.com 上运行 Zend Framework 应用程序(所以服务器配置应该没问题...)

索引页面工作正常,我修改了 application/controllers/IndexController.php 如下:

class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this->view->assign('hello', 'hello world!');
    }
}

在 application/views/scripts/index/index.phtml 我打印 $this->hello 并且一切正常。

但是如果我创建一个新的控制器,比如 application/controllers/UserController.php

class UserController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this->view->assign('name', 'Albert');
    }
}

我在 application/views/scripts/user/index.phtml 中创建了视图,并像在索引视图中一样打印 $this->name。

但是当我访问 http://myapp/user 时,我得到了一个 Not Found 错误...有什么问题?

【问题讨论】:

  • 检查您的重写规则 (.htaccess) framework.zend.com/manual/1.12/en/…
  • 我的bootstrap.php是空的,我应该在里面写什么?
  • 它为空时没问题;)只有当你必须自己引导东西时才需要

标签: php zend-framework


【解决方案1】:

1) 检查用户控制器的文件名是否包含第一个大写字母 UserController.php(不是 userController.php)

2) 检查 .htaccess 文件是否有正确的重写规则

3) 试试http://myapp/User(用户首字母大写)

4) 检查是否启用了默认路由。

5) 您是否创建并启用了错误控制器?

我认为配置中存在一些问题,可能在您的引导程序或 config.ini 中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 2015-02-08
    • 2015-12-06
    • 2012-12-28
    • 2017-05-29
    • 2013-09-09
    相关资源
    最近更新 更多