Frontcontroller在Zend Framework中无法正常工作

时间:2013-03-28 12:39:49

标签: zend-framework front-controller

我在zend框架中完全创建了模块(Admin)。现在我想在前端开始工作,这样我就可以从后端管理我的整个站点。但我无法得到解决方案。如果我在localhost上运行我的页面,那么它会自动调用后端的css和后端的主题,并显示错误消息“异常信息”,这里我将把我的application.ini文件代码

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

admin.bootstrap.path = APPLICATION_PATH "/modules/admin/Bootstrap.php"
admin.bootstrap.class = "Admin_Bootstrap"

appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1

resources.session.name = "ZendSession"
;resources.session.save_path = APPLICATION_PATH "/../data/session"
resources.session.use_only_cookies = true
resources.session.remember_me_seconds = 86400

resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
admin.resources.layout.layout = "admin"
admin.resources.layout.layoutPath = APPLICATION_PATH "/modules/admin/layouts/scripts"


resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "/views/"
resources.view[] =

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
resources.view[] =
admin.resources.view[] = 

resources.db.adapter = Pdo_Mysql
resources.db.params.username = root
resources.db.params.password = 
resources.db.params.dbname = myproject
resources.db.isDefaultTableAdapter = true

[staging : production]


[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1 

在bootstrap文件中,我没有任何函数或插件的初始化

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{


}

我为模块管理员创建了单独的bootsrap.php文件,如下所示: -

<?php
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
    /*protected function _initAppAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'names pace' => 'admin',
            'basePath' => APPLICATION_PATH . '/modules/admin/'
        ));
        return $autoloader;
    }*/

    protected function _initDoctype()
    {
      global $adminModuleCssPath;
      global $adminModuleJsPath;
      $this->bootstrap( 'view' );
      $view = $this->getResource( 'view' );

      $view->headTitle('Projects for learning');
      $view->headScript()->appendFile($adminModuleJsPath.'jquery-1.7.2.js');
      $view->headScript()->appendFile($adminModuleJsPath.'jquery-ui.js');     
      $view->headScript()->appendFile($adminModuleJsPath.'tinybox.js');
      $view->headScript()->appendFile($adminModuleJsPath.'common.js');
      $view->headLink()->appendStylesheet($adminModuleCssPath.'jquery-ui.css');
      $view->headLink()->appendStylesheet($adminModuleCssPath.'style.css');
      $view->headLink()->appendStylesheet($adminModuleCssPath.'theme.css');
      $view->headLink()->appendStylesheet($adminModuleCssPath.'tinybox.css');
      $view->doctype( 'XHTML1_STRICT' );
      //$view->navigation = $this->buildMenu();
    }

    protected function _initLayoutPlugin()
    {
         $layout = Zend_Controller_Front::getInstance();
         $layout->registerPlugin(new Admin_Plugin_AdminLayout());

    }

    protected function _initAuthPlugin()
    {
       $checkAuth = Zend_Controller_Front::getInstance();
       $checkAuth->registerPlugin(new Admin_Plugin_CheckAuth(Zend_Auth::getInstance()));
    }

    protected function _initRouter()
    {
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController->getRouter();
        $route = new Zend_Controller_Router_Route(
                 ':module/:controller/:action/*',
                 array('module' => 'admin')
              );
        $router->addRoute('default', $route);

        $usersRoute = new Zend_Controller_Router_Route_Regex(
                      ':module/:controller/:action/(?:/page/(\d+)/?)?',
                      array(
                            'module' => 'admin',
                            'controller' => 'users',
                            'action' => 'index',
                            'page' => 1,
                            ),
                      array(
                              'page' => 1,
                            )
                    );

        $router->addRoute('users-index', $usersRoute);

    }

    protected function _initActionHelpers()
    { 
        Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . "/modules/admin/views/helpers");
        Zend_Controller_Action_HelperBroker::addPrefix('Admin_View_Helper');
    }

    /*protected function _initAutoload()
    {
        $autoloader = new Zend_Loader_Autoloader_Resource(array(
            'namespace' => '',
            'basePath' => APPLICATION_PATH."/modules/admin",
            'resourceTypes' => array(
                'form' => array(
                    'path' => 'forms',
                    'namespace' => 'Form',
                ),
                'model' => array(
                    'path' => 'models',
                    'namespace' => 'Model',
                ),
            )
        ));
        return $autoloader;
    }*/

}

我犯了错误,我不知道,我是Zend Framework的新手,请任何人帮我解决我的问题,所以我可以调用我的前端站点控制器和操作并使用后端模块管理它(admin )

1 个答案:

答案 0 :(得分:1)

每个请求都会调用所有模块的Bootstrap类。

如果您需要执行特定于模块的设置(例如,初始化视图),请注册带有routeShutdown()挂钩的前端控制器插件。在调度周期的那一刻,您知道正在调用哪个模块,因此您知道如何配置视图。

有关详细信息,请参阅this answer上的ZF1 module bootstrapping和MWOP的帖子。