Model class not found in zend framework project (quickstart)

What I did is

  • zf create a demo1 project on the command line
  • add lines to application.ini
    • appnamespace = "Application"
    • resources.layout.layoutPath = APPLICATION_PATH "/ layouts / scripts"
  • add layout with header and footer using partial () (they work fine)
  • create Data.php in the model directory and add this simple class

    <?php class Application_Model_Data{   }//Application for appnamespace 
    
  • then I tried to load this class (by creating an instance) from index index index action

    $ data = new Application_Model_Data ();

  • but when I test it even at this level, it gives an error

    Fatal error: class 'Application_Model_Data' was not found in C: \ Zend \ ... \ IndexController.php

Question

  • I want to add an autoloader to load models into the application (I do not use modules)
  • , ,

, , ,

+3
5

!!

bootstrap:

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

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

Bootstrap, :

protected function _initResourceAutoloader()
{
     $autoloader = new Zend_Loader_Autoloader_Resource(array(
        'basePath'  => 'path/to/application/directory',
        'namespace' => 'Application_',
     ));

     return $autoloader;
}

Zend , DbTable, , ..

+2

:

protected function _initDefaultModuleAutoloader()
{ 

    $resourceLoader = new Zend_Application_Module_Autoloader(array(
        'namespace' => '',
        'basePath'  => APPLICATION_PATH,
    ));

    return $resourceLoader;

}

"Data.php"

Data.php :

class Model_Data extends Zend_Db_Table_Abstract {.....}

:

$data = new Model_Data();

: -)

+2

, autoloadernamespaces.0 = 'Application' appnamespace

/library/Application/Model/Data.php

"models" .

0

.php , , -

0
source

Source: https://habr.com/ru/post/1737655/


All Articles