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

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向