2014-01-21 64 views
0

我正在使用zend框架1.12.3。控制器在zend中不起作用

的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 显示错误'找不到页面'和'消息:无效控制LER规定(管理员)“

+0

显示您的.htaccess文件 – emaillenin

+0

您是否拥有AuthAction的相关视图文件auth.phtml? – user466764

回答

1

$_SERVER['REQUEST_URI']等于到 '/管理/',当您访问 '/管理/ auth /中',所以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') 
    ); 
} 
+0

谢谢。它正在工作 –