I am getting fatal error after adding the action helper class. I am trying to load layout corresponding to called layout. Following is my code snippet:
First of all i added a helper class under application/controller/helpers:
class Zend_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract {
public $pluginLoader;
public function __construct()
{
// TODO Auto-generated Constructor
$this->pluginLoader = new Zend_Loader_PluginLoader ();
}
public function preDispatch()
{
$bootstrap = $this->getActionController()->getInvokeArg('bootstrap');
$config = $bootstrap->getOptions();
$module = $this->getRequest()->getModuleName();
if (isset($config[$module]['resources']['layout']['layout'])) {
$layoutScript = $config[$module]['resources']['layout']['layout'];
$this->getActionController()->getHelper('layout')->setLayout($layoutScript);
}
}
}
Then i added a loader in bootstrap.php:
protected function _initLayoutHelper() {
$this->bootstrap('frontControl开发者_StackOverflowler');
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
$layout = Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_Layout());
}
Following is my application.ini:
[production]
autoloaderNamespaces.tree = "Tree_"
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.helperDirectory = APPLICATION_PATH "/controllers/helpers"
resources.modules[] = ""
contact.resources.frontController.defaultControllerName = "index"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = layout
admin.resources.layout.layout = admin
#admin.resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
While running this code i am getting following errors:
Warning: include(Zend\Controller\Action\Helper\LayoutLoader.php) [function.include]: failed to open stream: No such file or directory in D:\personal\proj\renovate\library\Zend\Loader.php on line 83
Warning: include() [function.include]: Failed opening 'Zend\Controller\Action\Helper\LayoutLoader.php' for inclusion (include_path='D:\personal\proj\renovate\application/../library;D:\personal\proj\renovate\library;.;C:\php5\pear') in D:\personal\proj\renovate\library\Zend\Loader.php on line 83
Fatal error: Class 'Zend_Controller_Action_Helper_LayoutLoader' not found in D:\personal\proj\renovate\application\Bootstrap.php on line 33
Kindly let me know, how can i come out from this issue. I am beginner in Zend Framework.
Seems like you have invalid include_path
Try insert this in the index.php:
define('ROOTDIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('LIBDIR', realpath(ROOTDIR . '../library') . DIRECTORY_SEPARATOR);
set_include_path(implode(PATH_SEPARATOR, array_merge(explode(PATH_SEPARATOR,ini_get('include_path')), array(LIBDIR))));
This works for directory structure like:
application/ library/ - Zend/ httpdocs/ - index.php
I think include path is valid. Following is my index.php
Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
Ensure library/
is on include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'),get_include_path(),)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();
精彩评论