SoluableNonagon
SoluableNonagon

Reputation: 11752

Zend Framework Bootstrap.php, Database Model, and Form

So I am working on a sample database project. I have a LoginController.php, a Faculty database, and a login page (phtml).

I get the error Fatal error: Class 'Faculty_DB' not found in /usr/local/zend/apache2/htdocs/InternProject1/application/controllers/LoginController.php on line 25

In the LoginController.php I have the following (plus some more):

public function indexAction()
{
    $login = new Form_Login();
    //$this->view->login = $login; 

    $request = $this->getRequest();
    if($request->isPost())
    {
        $data = $request->getPost();
        //$this->isValid(
        if($this->getRequest()->getPost())
        {
            $username = $request->getParam('username');
            $password = $request->getParam('password');
            // echo " What you entered is: $username and $password";
//line 24       
            $faculty = new Faculty_DB();
//then conditions for validation.

This references

class Faculty_DB extends Zend_Db_Table_Abstract

which is located in application/models/ directory

I have the following in Bootstrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    protected function _initAutoload()
    {
        $autoLoader = Zend_Loader_Autoloader::getInstance();
        $autoLoader->registerNamespace(array('App_'));
        $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
            'basePath'  => APPLICATION_PATH,
            'namespace' => '',
            'resourceTypes'     =>
                array('form'=>
                    array('path'        => 'forms/',
                        'namespace'     => 'Form_'
                    ),
                ),
            ));
        return $autoLoader;         
    }
}

Any clue on how to fix this? I tried the following:

 protected function _initResourceAutoloader()
 {
     $autoloader = new Zend_Loader_Autoloader_Resource(array(
         'basePath'  => APPLICATION_PATH,
         'namespace' => 'Application',
     ));

     $autoloader->addResourceType( 'model', 'models', 'Model');
     return $autoloader;
 }

but when I do that, it tells me it can't find my Login_Form;

Upvotes: 0

Views: 314

Answers (1)

drew010
drew010

Reputation: 69977

Given that your application namespace is Application, try:

  • Put your faculty DB class in application/models/Faculty.php
  • Name it Application_Model_Faculty
  • Extend it from Application_Model_DbTable_Faculty
  • Put the DbTable class in application/models/DbTable/Faculty.php

Since you are using Zend_Application, it will take care of setting up the autoloader and special prefixes like Form_, Model_, Plugin_ etc for you, so you can safely remove the _initAutoload and _initResourceAutoloader from your Bootstrap.

Upvotes: 3

Related Questions