zend框架重定向问题:指定的控制器无效

时间:2014-04-02 09:39:51

标签: php mysql .htaccess zend-framework

我正在zend framework 1.12中开发一个项目

如果我将所有文件保存在根文件夹中,一切正常,但如果创建一个新文件夹并移动所有文件,则无效。

以下是我的文件夹结构 应用 图书馆 上市 的index.php htaccess的

的.htaccess

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^js/(.*)$     public/js/$1 [L]
RewriteRule ^images/(.*)$     public/images/$1 [L]
RewriteRule ^css/(.*)$     public/css/$1 [L]
RewriteRule ^.*$ index.php [NC,L]

应用/配置/的application.ini

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.frontController.baseUrl = "/"

resources.session.remember_me_seconds = 864000


[staging : production]

[testing : production]

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root123"
resources.db.params.dbname = "labs"
resources.db.isDefaultTableAdapter = true
resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug
includePaths.models = APPLICATION_PATH "/models/"
resources.frontController.baseUrl = "/"

如果我移动labs中的所有文件夹/并将application.ini更改为
    resources.frontController.baseUrl =" / labs /"

http://domainname/  : Works fine     
https://domainname/labs  : gives error

如何解决这个问题。我想将所有文件放在新文件夹中,以便在root中我可以创建更多项目。

ERROR

An error occurred
Page not found
Exception information:

Message: Invalid controller specified (labs)
Stack trace:

#0 /var/www/html/labs/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /var/www/html/labs/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 /var/www/html/labs/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 /var/www/html/labs/index.php(30): Zend_Application->run()
#4 {main}  

Request Parameters:

array (
  'controller' => 'labs',
  'action' => 'index',
  'module' => 'default',
)  

2 个答案:

答案 0 :(得分:0)

也许您必须在配置文件中更改“baseUrl”。

resources.frontController.baseUrl = "/labs/"

也许是这样的:How to set baseUrl

答案 1 :(得分:0)

无需更改.htaccess中的任何内容

application.ini更改为
resources.frontController.baseUrl =" / labs"

在bootsrap.php中添加以下功能,您将完成。

protected function _initBaseUrl()
    {
        $options = $this->getOptions();
        $baseUrl = isset($options['settings']['baseUrl']) 
            ? $options['settings']['baseUrl']
            : null;  // null tells front controller to use autodiscovery, the default
        $this->bootstrap('frontcontroller');
        $front = $this->getResource('frontcontroller');
        $front->setBaseUrl($baseUrl);
    }