0
votes

I have tried many different ways to solve this that I have found online but they have not worked, so please can someone help me.

I am getting this error

Fatal error: Class 'Admin_Form_Login' not found in pathToProject/modules/admin/controllers/LoginController.php on line 13

my project is

Application

--- modules

------admin

--------controllers

--------forms

--------models

--------views

------default

--------controllers

--------forms

--------models

--------views

------aboutus

--------controllers

--------forms

--------models

--------views etc etc

My Controller

class Admin_LoginController extends Zend_Controller_Action
{

  public function init()
  {
     /* Initialize action controller here */
  }

  public function indexAction()
  {
      $form = new Admin_Form_Login();
      $this->view->form = $form;
      // action body
  }
}

My Form

class Admin_Form_Login extends Zend_Form
{

public function init()
{
    /* Form Elements & Other Definitions Here ... */

    $this->setAction("/admin/index/login")->setMethod("post");

    $username = new Zend_Form_Element_Text('username');
    $username->setLabel('Username')
    ->setOptions(array('size' => '30'));


    $password = new Zend_Form_Element_Password('password');
    $password->setLabel('Password')
    ->setOptions(array('size' => '30'));


    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setLabel('Log in')
    ->setOptions(array('class' => 'submit'));

    $this->addElement($username)
    ->addElement($password)
    ->addElement($submit);


}


}

MY Bootstrap.php

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initAutoload() {
        $autoloader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Admin_',
        'basePath' => APPLICATION_PATH."/modules/admin",
    ));
    return $autoloader;
    }
}

Here is my App ini maybe something in there

[bootstrap]

Autoloadernamespaces[] = "Admin_"
Autoloadernamespaces[] = "Default_"
Autoloadernamespaces[] = "Aboutus_"

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultModule = "default"
resources.modules[] = ""

resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "/views/"

bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.prefixDefaultModule = "1"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

admin.resources.layout.layout = layout
admin.resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
default.resources.layout.layout = default
default.resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

[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 my view

$this->form

Thanks for any help.


I added the following in the production part ok my application.ini and it started worked Not sure why.

Autoloadernamespaces[] = "Admin_"
Autoloadernamespaces[] = "Default_"
Autoloadernamespaces[] = "Aboutme_"

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultModule = "default"
resources.modules[] = ""

resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "/views/"

bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
3
Your Admin_Bootstrap, presumably stored in application/modules/admin/Bootstrap.php, extends Zend_Application_Module_Bootstrap, which registers its own resource autoloader. You could probably remove your custom Admin_Bootstrap::_initAutoload() method.David Weinraub
Is your form class at application/modules/admin/forms/Login.php?Tim Fountain
yes it is at application/modules/admin/forms/Login.phpDavid

3 Answers

0
votes

Listen to Dave, empty your Admin_Bootstrap class. If you need any _init methods put them in your application level bootstrap. All bootstrap classes run on every request anyway, so put any _init methods at the application level to prevent inadvertent overrides.

Ensure you module bootstrap is at application/modules/admin/Bootstrap.php (every module needs a bootstrap) this ensure that the resource autoloaders work correctly. Forms are a predefined resource in the autoloader so no _init method is needed.

Ensure your application.ini includes the minimum required to activate modules:

resources.modules = ""
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

and lastly don't forget to echo in your views:

$this->form

should be:

echo $this->form

Good Luck!

0
votes

This work for me:

in application/configs/application.ini

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""

in application/Bootstrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    /**
     * @return Zend_Application_Module_Autoloader
     */
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array('namespace' => '', 'basePath' => APPLICATION_PATH));
        return $autoloader;
    }
}

in modules/admin/Bootstrap.php

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{

}

The login form must reside in modules/admin/forms and the controller in modules/admin/controllers.

I hope to check out was helpful!

-1
votes

Try this:

protected function _initAutoload() {
    $autoloader = new Zend_Application_Module_Autoloader(array(
        'namespace' => '',
        'basePath' => APPLICATION_PATH,
    ));
    return $autoloader;
}

There's no namespace (only if you had one i.e. Application_).

As for the config file:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =

resources.layout.layout = "layout"
default.resources.layout.layoutPath = "/views/layout"
admin.resources.layout.layoutPath = "/views/layout" 

[staging : production]


[testing : production]

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1