Zend, cannot find model from the Bootstrap - php

I'm trying to put a model into the Zend Registry from the main application bootstrap file:
public function _initRegistry()
{
$this->bootstrap('db');
$processmanager = new Systems_Model_Process();
Zend_Registry::set('processmanager', $processmanager);
}
For some reason, I'm met with the following errors:
Warning: include_once(Systems/Model/Process.php) [function.include-once]: failed to open stream: No such file or directory in /home/planetxg/public_html/dash/library/Zend/Loader.php on line 146
Warning: include_once() [function.include]: Failed opening 'Systems/Model/Process.php' for inclusion (include_path='/home/planetxg/public_html/dash/application/../library:/home/planetxg/public_html/dash/library:.:/usr/lib/php:/usr/local/lib/php') in /home/planetxg/public_html/dash/library/Zend/Loader.php on line 146
Fatal error: Class 'Systems_Model_Process' not found in /home/planetxg/public_html/dash/application/Bootstrap.php on line 20
The model in question is in the following location:
application/modules/Systems/models/Process.php
Is there something simple I'm missing or not setting here at all? I should add everything works fine when calling models normally within controllers.
Here's my main ini block if it helps:
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 = 0
resources.frontController.actionHelperPaths.Utilities = APPLICATION_PATH "/controllers/Helpers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
autoloaderNamespaces[] = "CreativeLaunch_"
autoloaderNamespaces[] = "Systems_"

You need a module bootstrap class at application/modules/systems/Bootstrap.php which extends Zend_Application_Module_Bootstrap. This will setup module autoloading. Also your module folder should be lowercase - application/modules/systems.
The module resource needs to have run before your _initRegistry method in the main bootstrap file, so change the first line of that method to:
$this->bootstrap(array('db', 'modules'));
Everything else looks good.

Related

Zend (v1) Autoloader does not work

I am a bit lost right now. I try to establish my own library but the autoloader seems not to be working somehow.
This exaple here was the closest I found but all the solutions did not work for me.
This is my folder structure.
-application
|_modules
|_vita
|_controllers
|_IndexController.php
-data
-docs
-library
|_ND
||_Model
| |_Vita
| |_Vita.php
|_Zend
-public
-tests
This is my bootstrap.
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
...
protected function _initAutoloader()
{
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('ND_');
return $loader;
}
...
}
This is my complete application.ini (I am aware that the autoloaderNamespaces instruction is double with the one in the bootstrap but it does not work with both or each of them alone)
[production]
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"
; automatic loading of libraries
autoloaderNamespaces[] = "ND_"
phpSettings.date.timezone = "Europe/Berlin"
;resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/index/controllers"
;resources.frontController.params.displayExceptions = 0
;appnamespace = "Application"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.prefixDefaultModule = true
resources.frontController.defaultModule = "index"
resources.frontController.throwerrors = false
resources.frontController.params.displayExceptions = 0
; resources (modules)
resources.modules[] = ""
resources.view[] = ""
; resources (layout)
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "main"
; db settings
resources.db.adapter = "PDO_MYSQL"
resources.db.isDefaultAdapter = true
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "nd"
[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
This is my Controller where I try to instantiate the class "Vita"
But I always receive this Error: "Fatal error: Class 'ND_Model_Vita_Vita' not found in C:\xampp\htdocs\ND\application\modules\vita\controllers\IndexController.php on line 17"
class Vita_IndexController extends Zend_Controller_Action
{
public function init()
{
$this->view->headTitle('Vita');
}
public function indexAction()
{
/* Just to try if the Loader is working for the Zend library -> it works */
$this->newForm = new Zend_Form();
$this->mdlVita = new ND_Model_Vita_Vita();
Zend_Registry::get('log')->info($this->mdlVita->test());
}
}
And this is the Vita Class
class ND_Model_Vita_Vita
{
public function test()
{
return 'Is working';
}
}
Is there something I might have overlooked or I have to have in mind when using modules?
I am thankful for any suggestion.
EDIT : I narrowd down the issue to have something to do with the xampp environment. I pushed the project to a live-apache location and there it worked.

How to access my modules in Zend Framework 1.12

New to Zend!!
I have created a Zend projects with 2 modules, 1.defaule and 2.test
Structure
application +
|__ Modules
|_default
controllers
IndexController.php
ErrorController.php
models
views
|_test
controllers
IndexController.php
models
views
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 = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = "test"
Finally in my test/controllers/IndexController.php
class Test_IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
echo "This is Test Index Controller";
}
}
I can access default module with no problems, but when I try
dev.local/test/index
It says Application Error
Any Suggestions why its doing this??
First make
resources.frontController.params.displayExceptions = 1
It will give you the exact error message in the controller, and whats in your views directory in your test module? You need to have a script template file for index action. Just guessing, coz faced similar issue recently.

how to add another folder level to send framework autoloader?

i have this simple setup
-controllers
IndexController.php
here somewhere i call new Application_Model_Sites_Sites()
+layouts
-models
-sites
Sites.php
class Application_Model_Sites_Sites
{ .. }
+library
+public
and i get Fatal error: Class 'Application_Model_Sites_Sites' not found in ..
The strange thing is that under xampp in windows it works perfect, but when i place it on a linux server i get that error
I'm thinking i need to tell zend about those sub-folders, but i have the impression that it should know about them because i use them in the class name
Any ideas what am i missing?
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.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[]=
resources.view.helperPath.Zend_View_Helper = APPLICATION_PATH "/views/helpers"
[staging : production]
[testing : production]
and by bootstrap is empty for now
shouldnt it be Models with an s - Application_Models_Sites_Sites?

Zend Framework Plugin in INI is not run

The plugin declared in my application.ini file is not being triggered. I can install plugins the old way via the Bootstrap file, but I'd prefer to keep it in the INI. It doesn't ever load that file, no exception thrown, nothing.
I've tried adding .class to the declaration, but nothing.
application.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "America/Chicago"
includePaths.library = APPLICATION_PATH "/../library:/Users/shane/Sites/doctrine1/lib"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
;resources.modules = ""
resources.frontcontroller.defaultmodule = default
resources.frontcontroller.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 1
resources.doctrine.connections.default.dsn = "mysql://root:root#127.0.0.1/newfb"
resources.doctrine.manager.attributes.attr_model_loading = "model_loading_zend"
;resources.doctrine.manager.attributes.attr_use_native_enum = true
pluginpaths.ZFDoctrine_Application_Resource = "ZFDoctrine/Application/Resource"
autoloadernamespaces.0 = "Doctrine"
autoloadernamespaces.1 = "ZFDoctrine"
autoloadernamespaces.2 = "dummy"
autoloadernamespaces.3 = "ZFDebug"
resources.frontController.params.prefixDefaultModule = false
;; This should work, but it doesn't, not sure why
resources.frontController.plugins.messages = "dummy_Plugins_Messages"
library/dummy/Plugins/Messages.php
<?php
class dummy_Plugins_Messages extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request) {
parent::preDispatch($request);
throw new Exception('HERE');
}
}
The index.php is the standard Zend_Application created using the Zend_Tool
Have you registered the 'Faxxbachs_Plugins' namespace as a plugin path?
pluginpaths.Faxxbachs_Plugins = /path/to/Faxxbachs/Plugins
Also FYI, I noticed in your example, you were inconsistent in your casing of frontController. ZF tends gets whiny about case, so make sure you're consistent.

Zend Framework load plugin

I am trying to load a Plugin but I get the following error:
Fatal error: Class
'Site_Plugin_ViewSetup' not found in
C:\dev\library\Zend\Application\Resource\Frontcontroller.php
on line 92
I configured the file (last line):
[production]
includePaths.library = APPLICATION_PATH "/../lib"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.frontController.plugins.viewsetup = "Site_Plugin_ViewSetup"
And in \lib\Site\Plugin I have ViewSetup.php
class Site_Plugin_ViewSetup extends Zend_Controller_Plugin_Abstract
{ ... }
I looked at zend docs but could not fid how to properly load a plugin. Does it have to be in the 'library' directory or could I place the 'plugin' folder in the same directory where my 'views' and 'controllers' folders are.
UPDATE
I added autoloaderNamespaces and it worked.
autoloaderNamespaces[] = "site"
resources.frontController.plugins.viewsetup
= "site_Plugin_ViewSetup"
I don't get why it worked since I already had "site_" in class name.
Actually you can add this line to your ini:
autoloaderNamespaces[] = "Site_"
You should be able to just put it in the Site/Plugin/ViewSetup.php file in your library.

Categories