简体   繁体   中英

Frontcontroller is not working properly in Zend Framework

I have created module(Admin) completely in zend framework. Now I want to start work in front end so I can manage my whole site from backend. But I am unable to getting solution for this. If I run my page at localhost, then it automatically call the css of backend and theme of backend with error message 'Exception Information', Here I am putting my application.ini file code

[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 

In bootstrap file I doesn't have initialization of any function or plugin

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{


}

I have created separate bootsrap.php file for module admin like this:-

<?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;
    }*/

}

Where I have made error, I don't know, I am new with Zend Framework, please anyone help me to resolve my this problem, so I can call my front site controllers and actions and manage it with backend module(admin)

Bootstrap classes for all modules are called on every request.

If you need to perform module-specific settings (initializing your view, for example), then register a front-controller plugin with a routeShutdown() hook. At that point in the dispatch cycle, you know which module is being called so you know how you want to configure your view.

For more information, see this answer and MWOP's post on ZF1 module bootstrapping .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM