dqt83336 2014-01-21 11:36
浏览 33
已采纳

控制器动作不在zend中工作

i am using zend framework 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;
    }

Admin controller :

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

when i access the url: http://pro.localhost/admin/ - this is working

but when i access the url : http://pro.localhost/admin/auth showing error 'Page not found' and 'Message: Invalid controller specified (admin) '

  • 写回答

1条回答 默认 最新

  • dongqun5769 2014-01-21 11:53
    关注

    $_SERVER['REQUEST_URI'] isn't equal to '/admin/' when you visit '/admin/auth/', so APPLICATION_PATH is being defined as the store path instead. You should be checking for whether $_SERVER['REQUEST_URI'] begins with '/admin/'. And you shouldn't need a switch statement to check two conditions.

    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')
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM