I have created a module 'admin' . I also created a layout for this admin module. How can I permanently attach this layout to 'admin' module. Can some one suggest me where and how can I write code for this purpose. Whether it would be in bootstrap file ?
If this is a module like you say you can simply add a layout.phtml file into the module's layout/scripts/ folder.
If you have a different name for your layout.phtml like admin.phtml you simple add the following in your controller
$this->_helper->layout->setLayout('admin');
It should and will check first the module's layout folder and then the default folder.
you can specify alternative path for layout scripts:
if (!$registered) {
//for PUBLIC role
Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH.'/layouts/scripts/pub');
} else {
//For registered users
Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH.'/layouts/scripts');
}
In your bootstrap file
protected function _initAutoloader() {
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/modules/default'), array(
'namespace' => 'Admin',
'basePath' => APPLICATION_PATH . '/modules/admin'
)
);
return $autoloader;
}
application.ini
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
includePaths.library = APPLICATION_PATH "/../library"
appnamespace = "Default"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.defaultModule = "default"
resources.frontController.defaultController = "index"
resources.frontController.defaultAction = "index"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "layout"
resources.modules = ""
resources.view[] =
and in each controller of admin you need to add this line to the init function to change the layout.
$this->_helper->layout()->setLayout("admin");
Related
I am a new user to zend framework and i tried the other solutions given in stack overflow for similar questions.
This is my index.php
<?php
date_default_timezone_set('UTC');
// 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') : 'production'));
// 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();
When i echo set_include_path, this is the response i got,
:.:/usr/lib64/php
Do i have to install zend framework in my new Cent OS ?
My library folder is, in the same directory the index.php reside.
/home/eat/public_html/index.php
/home/eat/public_html/library
/home/eat/public_html/library/Zend
Update..
When i hardcoded the path as, set_include_path('/home/eat/public_html/library/');
I started getting a new error. which is,
Warning: require_once(Zend/Loader/Autoloader.php): failed to open stream: No such file or directory in /home/eat/public_html/library/Zend/Application.php on line 80
Fatal error: require_once(): Failed opening required 'Zend/Loader/Autoloader.php' (include_path='/home/eat/public_html/library/') in /home/eat/public_html/library/Zend/Application.php on line 80
**Update 2**
Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Resource matching "multidb" not found' in /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php:691 Stack trace: #0 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(626): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('multidb') #1 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap('multidb') #2 /home/eat/public_html/application/Bootstrap.php(58): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap('multidb') #3 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initApplication() #4 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('application') #5 /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Z in /home/eat/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php on line 691
Application.ini
[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
eat.application.base.url = "eat.com"
eat.application.admin.url = "admin.eat.com"
eat.application.api.url = "api.eat.com"
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.prefixDefaultModule = "1"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
autoloaderNamespaces[] = "Eat_"
resources.modules = ""
phpSettings.date.timezone = "GMT"
eat.application.salt = "sd876fs89df";
resources.view[] =
resources.view.helperPath.Eat_View_Helper = APPLICATION_PATH "/../library/Eat/View/Helper"
;;; Databases
;;;;; Layouts
resources.layout.layoutPath = APPLICATION_PATH "/views/layouts"
resources.layout.layout = web/web
nexva.applicaiton.fileUploadDirectory = APPLICATION_PATH "/../files"
;;;; ReCaptcha ;;;;
recaptcha.private_key = 6LfL7rsSAAAAAKgtKWsMk4hmA2DSVq0ODcyJFRjs
recaptcha.public_key = 6LfL7rsSAAAAANiaZOQN7LOoCGAXh29rHTZPRoVa
[staging : production]
eat.application.base.url = "eat.com"
eat.application.admin.url = "admin.eat.com"
eat.application.api.url = "api.eat.com"
;;; Databases
resources.multidb.default.adapter = mysqli
resources.multidb.default.host = "localhost"
resources.multidb.default.username = "eat"
resources.multidb.default.password = "eat"
resources.multidb.default.dbname = "eat_main"
resources.multidb.default.default = true
[development : production]
eat.application.base.url = "eat.com"
eat.application.admin.url = "admin.eat.com"
eat.application.api.url = "api.eat.com"
;;; Databases
resources.multidb.default.adapter = mysqli
;resources.multidb.default.host = "192.168.1.253"
resources.multidb.default.host = "localhost"
resources.multidb.default.username = "eat"
resources.multidb.default.password = "eat"
resources.multidb.default.dbname = "eat_main"
resources.multidb.default.default = true
[development-alt : development]
Update 3
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function __construct($application)
{
parent::__construct($application);
}
protected function _initAutoload()
{
Zend_Controller_Action_HelperBroker::addPrefix('Eat_Controller_Action_Helper');
$autoloader = new Zend_Application_Module_Autoloader(
array(
'namespace' => '',
'basePath' => APPLICATION_PATH,
'resourceTypes' => array(
'form' => array(
'path' => 'forms',
'namespace' => 'Form',
),
'model' => array(
'path' => 'models',
'namespace' => 'Model',
),
)
)
);
return $autoloader;
}
protected function _initLayoutHelper()
{
$this->bootstrap('frontController');
$layout = Zend_Controller_Action_HelperBroker::addHelper(new Eat_Controller_Action_Helper_LayoutLoader());
}
protected function _initApplication()
{
$config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/application.ini", APPLICATION_ENV);
Zend_Registry::set("config", $config);
$locale = new Zend_Locale();
Zend_Registry::set('Zend_Locale', $locale);
//init DB connection
try {
$this->bootstrap('multidb');
$multiDb = $this->getPluginResource('multidb');
$db = $multiDb->getDb('default');
$db->setFetchMode(Zend_Db::FETCH_OBJ);
$db->getConnection();
$db->getProfiler()->setEnabled(true);
Zend_Registry::set('db', $db);
//Just making everything UTF8. This is a hack, need to find the proper Zend way
$db = Zend_Registry::get('db');
$db->query('SET NAMES "utf8"')->execute();
} catch (Zend_Db_Adapter_Exception $e) {
die("Error connecting to database: " . $e->getMessage());
}
}
public function _initRoutes()
{
/*
$router = Zend_Controller_Front::getInstance()->getRouter();
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', APPLICATION_ENV);
$router->addConfig($config, 'resources');
$routes['featured'] = new Zend_Controller_Router_Route(
'featured/:id',
array('controller' => 'index', 'action' => 'featured', 'id' => null)
);
Zend_Controller_Front::getInstance()->getRouter()->addRoutes($routes);
*/
}
protected function _initLanguages()
{
}
//Initilaize zend ACL
public function _initAcl()
{
//Omit the process in CLI mode
if (php_sapi_name() != 'cli')
{
$helper = new Eat_Controller_Action_Helper_AclDefault();
$helper->setRoles();
$helper->setResources();
$helper->setPrivilages();
$helper->setAcl();
//Register the ACL plugin - Then it will be called automatically,whenever an acion is called
$this->bootstrap('frontController');
$frontController = Zend_Controller_Front::getInstance();
// $frontController->registerPlugin(new Eat_Plugin_Acl());
}
}
//Initialize error controller
public function _initErrorSwitcher()
{
$this->bootstrap('frontController');
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new Eat_Plugin_ErrorControllerSwitcher());
}
protected function _initZFDebug()
{
// Enabling this method seems to break autocomplete. Use only when needed
$autoloader = Zend_Loader_Autoloader::getInstance ();
$autoloader->registerNamespace ( 'ZFDebug' );
$db = Zend_Registry::get ( 'db' );
$cache = Zend_Cache::factory ( 'Core', 'File' );
//Zend_Controller_Front::getInstance()->getBaseUrl();
//APPLICATION_PATH
$options = array ('plugins' => array ('Variables', 'Database' => array ('adapter' => $db ), 'File' => array ('basePath' => Zend_Controller_Front::getInstance ()->getBaseUrl () ), 'Memory', 'Time', 'Registry', 'Cache' => array ('backend' => $cache->getBackend () ), 'Exception' ) );
$debug = new ZFDebug_Controller_Plugin_Debug ( $options );
$this->bootstrap ( 'frontController' );
$frontController = $this->getResource ( 'frontController' );
//$frontController->registerPlugin ( $debug );
}
}
your application & library folder should be located outside of public_html:
this code looks for "application" folder in parent("/../") folder (relative to index.php):
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
This code adds "/../library" to include path:
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/library'),
get_include_path(),
)));
So either move application & library folders outside of public_html, or remove /.. from the APPLICATOIN_PATH define (but this is undesirable as it will make your app less secure)
UPD. if you still get the error, make sure you have this file along with other Zend files:
library/Zend/Loader/Autoloader.php
If not, please download latest version of Zend Framework:
ZF1:
http://downloads.zend.com/framework/1.12.10/ZendFramework-1.12.10.tar.gz
ZF2:
http://downloads.zend.com/framework/2.3.4/ZendFramework-2.3.4.tgz
You can either save it to "library" folder or unarchive it to /usr/lib64/php (so it's saved as /usr/lib64/php/Zend/), this way you won't need to have this folder for each project
UPD2 search for
getResource('multidb')
in your code (application folder), then try to add
$this->bootstrap('multidb');
above that..
My guess is that either your Zend Framework version is different from used in original software, or your directory structure is invalid, could you try to move library&application folders outside of public_html?
UPD3 you can also drop me an email (mstrokin at gmail.com) and I'll try to fix that for you, I love debugging :)
UPD4 try to change "getPluginResource" to "getResource"
A possible issue would be permissions for the "library" directory.
And it affects Linux users in most cases.
If you are Linux user you may need to change them
sudo chmod 755 -R path_to_project/library
If you still experience that error then you should play around with either php.ini settings or the "library" folder location.
I have a problem with setting up my Zend Framework application on live server. It works alright on localhost.
My live server address where I have the application is:
http://www.domainname.com/new/
Everything is OK until I try to access my admin module at URL http://www.domainname.com/new/admin , then I get the error below.
Any ideas?
An error occurred
Page not found
Exception information:
Message: Invalid controller specified (index)
Stack trace:
#0 /data/www/www.domainname.com/public_html/new/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /data/www/www.domainname.com/public_html/new/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 /data/www/www.domainname.com/public_html/new/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 /data/www/www.domainname.com/public_html/new/index.php(27): Zend_Application->run()
#4 {main}
Request Parameters:
array (
'module' => 'admin',
'controller' => 'index',
'action' => 'index',
)
Include paths in index.php are set correctly (library and everything else is loaded), index.php file here:
// 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') : 'production'));
set_include_path('library');
// Define upload path
if (!defined('UPLOAD_PATH'))
define('UPLOAD_PATH', realpath(dirname(__FILE__)) . '/upload/');
/** 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();
Bootstrap.php file:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype(){
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
}
protected function _initTimeZone(){
$date = $this->getOption('date');
date_default_timezone_set($date['timezone']);
}
protected function _initLayoutHelper(){
$this->bootstrap('frontController');
Zend_Controller_Action_HelperBroker::addHelper(
new Jakub_Controller_Action_Helper_LayoutLoader());
}
protected function _initFlashMessenger(){
$flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
if ($flashMessenger->hasMessages()) {
$view = $this->getResource('view');
$view->messages = $flashMessenger->getMessages();
}
}
protected function _initAuth(){
$this->bootstrap('session');
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$view = $this->getResource('view');
$view->user = $auth->getIdentity();
}
return $auth;
}
}
Application.ini file:
[production]
webhost = "http://www.domainname.com/new"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
includePaths.library = APPLICATION_PATH "/../library"
date.timezone = "Europe/Bratislava"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
autoloadernamespaces.nette = "Nette_"
autoloadernamespaces.jakub = "Jakub_"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.view[] =
resources.view.helperPath.App_View_Helper = APPLICATION_PATH "/views/helpers"
resources.modules[] =
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/default/"
resources.layout.layout = default
admin.resources.layout.layoutPath = APPLICATION_PATH "/modules/admin/layouts/scripts/base/"
admin.resources.layout.layout = default
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
webhost = "http://domainname"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
In your admin module folder, check that IndexController.php exists within the "controllers" sub-directory.
If it does, then open IndexController.php and ensure that the class declaration does indeed declare the class "IndexController" (a common copy+paste pitfall)
Edit: Controller name should be Admin_IndexController, not just IndexController
try in your application.ini:
resources.frontController.moduleControllerDirectoryName = "controllers"
I also have this in my application.ini for my module app:
resources.frontController.params.prefixDefaultModule = ""
also does each module have it's own bootstrap?
<?php
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {
//put your code here
}
I was using an authetication controller my collegue prepared and I had the same problem, and I found the problem in the redirect of the controller.
if (!$this->_acl->isAllowed(Zend_Registry::get('user_role'), $module . ':' . $controller, $action)) {
$request->setModuleName('default')->setControllerName('authentication')->setActionName('login');}
This basically checkes if you are logged in and if you have the access rights to go to the specified controller, and if not, it redirects you to (in this case) default/authenticaion/index
Unfortunately the redirect parameters are not displayed in the error message.
I realized I do not have the controller I am redirecting to ready, so in some cases it might be the same problem.
I started out with models in a module called Api, using the following
classname/filename conventions:
filename: {project}/application/modules/api/models/Account.php
classname: Api_Model_Account
They were happily autoloading through the framework as expected.
I decided that some of these models would be better off,
organisationally speaking, in the application's models directory as they
could be used across multiple modules.
I moved them and renamed them:
filename: {project}/application/models/Account.php
classname: Application_Model_Account
However, they are not autoloading - PHP throws a class not found. I have checked and confirmed my
configuration ({project}/application/configs/application.ini):
[production]
appnamespace = "Application"
So, the application namespace is 'Application', but the models in the
application/models directory are not being autoloaded.
Just to make things that little bit crazier - the plugins in application/plugins are being autoloaded.
Testing:
<?php
class Application_Model_ExampleTest extends AMH_Test_PHPUnit_ControllerTestCase
{
public function testLoad()
{
$moduleModel = new Api_Model_Product();
$plugin = new Application_Plugin_ModuleErrorControllerSelector();
$applicationModel = new Application_Model_Example();
}
}
class AMH_Test_PHPUnit_ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
public function tearDown()
{
$this->resetRequest();
$this->resetResponse();
parent::tearDown();
}
}
Configuration:
[production]
appnamespace = "Application"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
includePaths.library = APPLICATION_PATH "/../library"
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "Australia/Adelaide"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.modules[] = ""
[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
Relevant folder paths:
<project name>/
application/
models/
Example.php
modules/
api/
models/
Product.php
plugins/
ModuleErrorControllerSelector.php
Error message:
PHP Fatal error: Class 'Application_Model_Example' not found in /var/www/accounts.amh.localhost/tests/application/models/ExampleTest.php on line 9
This is using Zend Framework 1.10 (package for Ubuntu 10.04)
Not sure why this way its not loading. But another suggestion is you can set the models in include path.
set_include_path('.'
. PATH_SEPARATOR . 'application/models'
. PATH_SEPARATOR . get_include_path()
);
This method needs to be in all tests to ensure the environment is properly bootstrapped:
public function setUp()
{
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
In the app-level Bootstrap, you could configure a resource loader:
protected function _initAutoloader(){
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' => 'Application',
'resourceTypes' => array(
'model' => array(
'namespace' => 'Model',
'path' => 'models',
),
),
));
}
In my case it was all about one capital letter.
Model_DbTable_User -> Model_DBTable_User fixed this bug.
Model_DbTable_User was working on my local but not on the server!
My application.ini looks like this:
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
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 = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
resourceses.includePaths.library = APPLICATION_PATH "/../../library"
resources.layout.layout = layout
admin.resources.layout.layout = admin
index.php looks like this
<?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(),
)));
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../../library'),
APPLICATION_PATH . '/modules/admin/models',
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();
My application/bootstrap.php looks like this:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initAutoload() {
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Admin_',
'basePath' => dirname(__FILE__) . '/modules/admin'
));
}
}
And finally my module Bootstrap looks like this:
<?php
class admin_Bootstrap extends Zend_Application_Module_Bootstrap {
}
I am trying to develop and administrator module. I have it set up under the folder application/modules. I get this error:
Warning: include_once(Zend\Paginator\Adapter\Select.php) [function.include-once]: failed to open stream: No such file or directory in E:\wamp\www\industrial\library\Zend\Loader.php on line 146
Warning: include_once() [function.include]: Failed opening 'Zend\Paginator\Adapter\Select.php' for inclusion (include_path='E:\wamp\www\industrial\application/../library;;E:\wamp\www\industrial\application/modules/admin/models;E:\wamp\www\industrial\library;.;C:\php5\pear') in E:\wamp\www\industrial\library\Zend\Loader.php on line 146
Fatal error: Class 'Zend_Paginator_Adapter_Select' not found in E:\wamp\www\industrial\application\modules\admin\controllers\UsersController.php on line 11
Can't understand what is wrong.
PS: i have used this tutorial to set up the module
There's no need to add include path to modules.
This is not needed at all:
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../../library'),
APPLICATION_PATH . '/modules/admin/models',
get_include_path(),
)));
But ensure that this include path contains the path to Zend Framework library.
Probably you are missing:
resources.modules[] =
in application.ini.
In addition to what takeshin said, you are NOT obeying the naming conventions....
Class names must always start with Uppercase Letter.
So change...
class admin_Bootstrap extends Zend_Application_Module_Bootstrap {}
to
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {}
Your way might work on windows but on linux it'll die...
Comment this line
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
Ok, this is driving me nuts!
I have a directory structure as follows:
application
- modules
-- default
--- controllers
--- models
---- DbTable
---- Cachmapper.php
--- views
My config file looks like this
[production]
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.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
The application seems to work, if I navigate to localhost, it correctly goes to the index controller. But, for some reason it refuses to load any models.
Fatal error: Class 'Model_Cachmapper' not found in .............................../application/modules/default/controllers/IndexController.php on line 26
Ideas?
Thanks
Here's a working version (one of them, at least), for ZF 1.10.x and probably earlier, too.
index.php
<?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') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
/** 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();
application.ini - the relevant parts
autoloadernamespaces[] = Zend_
includePaths.library = APPLICATION_PATH "/../library"
; Where will Zend_Application find the Bootstrap file
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
; Where are all the modules
resources.frontcontroller.moduledirectory = APPLICATION_PATH"/modules"
resources.modules[] = ""
; And which is the default module
resources.frontcontroller.defaultmodule = "default"
and in application/Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
/**
* Autoloader for the "public" module
*
* #return Zend_Application_Module_Autoloader
*/
public function _initPublicAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(
array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/modules/default'
)
);
return $moduleLoader;
}
}
I am a novice ZF user, so this may not be 'correct' but I have had no problems using DB Models this way.
My directory structure looks like this:
/
--/application
----/configs
----/controllers
----/forms
----/layouts
----/models
------/DbTable
In my application/public/index.php I have the following code:
...
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Application_');
require_once 'Zend/Loader/Autoloader/Resource.php';
$resources = new Zend_Loader_Autoloader_Resource(array(
'namespace' => 'Application',
'basePath' => APPLICATION_PATH
));
$resources->addResourceType('form','forms','Form');
$resources->addResourceType('model','models','Model');
$resources->addResourceType('dbtable','models/DbTable','Model_DbTable');
...
My application namespace is Application (if you couldn't tell).
My database models look like this (located in application/models/DbTable:
class Application_Model_DbTable_User extends Zend_Db_Table_Abstract
{
protected $_name = 'User';
protected $_primary = 'username';
}
class Application_Model_DbTable_WinLossTieScore extends Zend_Db_Table_Abstract
{
protected $_name = 'WinLossTieScore';
protected $_primary = 'id';
...
}
Also, the relevant portions of application/configs/application.ini:
appnamespace = "Application"
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
I would add a bootstrap class to the module as otherwise the module loader doesn't know about it.
class Default_Bootstrap extens Zend_Application_Module_Bootstrap
{
}
And store in applications/default/Bootstrap.php
http://akrabat.com/modules has some more info.
Add your models directory to your includePaths
I have:
includePaths.models = APPLICATION_PATH "/models"
I know, your models lies under your modules, but should be possible to do somehow. Maybe in the bootstrap instead of application.ini
Att.: Rob
Hi Rob,
Well i'm confused. Because i actually bought your book 'Zend Framework In Action'.
And in the bootstrap of the 'Places' app in the sourcecode, you have the following.
set_include_path(get_include_path()
. PATH_SEPARATOR . ROOT_DIR . '/library/'
. PATH_SEPARATOR . ROOT_DIR . '/application/models/'
. PATH_SEPARATOR . ROOT_DIR . '/application/forms/'
);
include 'Zend/Loader.php';
Zend_Loader::registerAutoload();
I know that the source is written for an older ZF version. My current app i'm working on is based on Zend_Application, and if i remove the models folder from my includePaths, the loader can't find my models.
Warning: include_once(Users.php) [function.include-once]: failed to open stream: No such file or directory in C:\Programmer\wamp\include\Zend\Loader.php on line 146