【问题标题】:controller Action not working in zend控制器动作在zend中不起作用
【发布时间】:2014-01-21 11:36:16
【问题描述】:

我正在使用 zend 框架 1.12.3。

index.php:

    switch(strtolower($_SERVER['REQUEST_URI'])) {
      case '/admin/':  
        define('APPLICATION_PATH',
        realpath(dirname(__FILE__) . '/../application/admin'));
      break;
      case '/store/':  
        define('APPLICATION_PATH',
        realpath(dirname(__FILE__) . '/../application/stoe'));
      break;
      default:  
        define('APPLICATION_PATH',
        realpath(dirname(__FILE__) . '/../application/store'));
      break;
    }

管理控制器:

    public function init()
    {
        /* Initialize action controller here */

    }

    public function indexAction()
    {
      $request = $this->getRequest();  

      $this->view->assign('title', 'Login Form');
      $this->view->assign('username', 'User Name'); 
      $this->view->assign('password', 'Password');
    }


    public function authAction()
    {
       echo 'test';exit;    
    }

当我访问网址时: http://pro.localhost/admin/ - 这是有效的

但是当我访问网址时: http://pro.localhost/admin/auth 显示错误“找不到页面”和“消息:指定的控制器无效(管理员)”

【问题讨论】:

  • 显示您的 .htaccess 文件
  • 您是否为 AuthAction 准备了相关的视图文件 auth.phtml?

标签: php zend-framework


【解决方案1】:
当您访问“/admin/auth/”时,

$_SERVER['REQUEST_URI']等于与“/admin/”,因此 APPLICATION_PATH 被定义为存储路径反而。您应该检查$_SERVER['REQUEST_URI'] 开始 是否以“/admin/”开头。而且您不需要 switch 语句来检查两个条件。

if (strpos(strtolower($_SERVER['REQUEST_URI']), '/admin/') === 0) {
    define(
        'APPLICATION_PATH',
        realpath(dirname(__FILE__) . '/../application/admin')
    );
} else {
    define(
        'APPLICATION_PATH',
         realpath(dirname(__FILE__) . '/../application/store')
    );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-21
    相关资源
    最近更新 更多