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.
Related
I have created a form named signin in a module named sign in zend framework version 1 and it says "Class 'Sign_Form_Signin' not found "
Here is form code:
<?php
class Sign_Form_Signin extends Zend_Form
{
public function init()
{
$this->setAction("/sign/in");
$this->setMethod("post");
$username=new Zend_Form_Element_Text("password");
$username->addValidator(new Zend_Validate_Alnum())
->setRequired(TRUE)
->setLabel("نام کاربری: ")
->setAttrib("size", "25");
$password=new Zend_Form_Element_Password("password");
$password->addValidator(new Zend_Validate_Alnum)
->setRequired(TRUE);
$submit=new Zend_Form_Element_Submit("submit");
$submit->setLabel("ورود");
$this->addElement($username);
$this->addElement($password);
}
}
Here is 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"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
resources.db.adapter = "PDO_MYSQL"
resources.db.params.dbname = "test"
resources.db.params.host = "localhost"
resources.db.params.port="8889"
resources.db.params.username = "root"
resources.db.params.password = "root"
resources.db.params.charset = "UTF8"
resources.frontController.moduleDirectory = APPLICATION_PATH "/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
and here is the controller code:
<?php
class Sign_IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
public function inAction()
{
$form=new Sign_Form_Signin();
$this->view->form= $form;
}
public function outAction()
{
// action body
}
}
Do you have any ideas that what the problem is?
If your name form is new Sign_Form_Signin();
You must to locate the class form in Sign/Form/Signin.php
Each _ in of the classname means a directory for the real path.
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.
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?
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.
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.