views:

280

answers:

3

The things I did is

  1. zf create project demo1 in command prompt
  2. add the lines to application.ini
    • appnamespace = "Application"
    • resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
  3. add a layout with header and footer using partial() (They are perfectly worked)
  4. create Data.php in models directory and add this simple class

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

    $data = new Application_Model_Data();

  6. but when I test it even in this level it gives an error

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

Question

  1. Do I want to add a autoloader to load models in the application( I'm not used modules)
  2. if not what was I missed to add

please help I'm stuck in the beginning,Thank you

A: 

in your application ini you should have autoloadernamespaces.0 = 'Application' instead of appnamespace

then your model would be in /library/Application/Model/Data.php

but why dont you use the default "models" folder in the suggested application structure.

Rufinus
no no data.php file placed in default model folderdemo1\application\models\Data.php
Dumindu
/library/Application/Model/Data.php ? no no this is not a library class.it'a simple model class.Thanks
Dumindu
please help me,I know how to add DBs and table classes to application.my IDE show that class on the right location but I can't access model classes from controllers.why? please.Thanks
Dumindu
if the model is in the models folder, the class name is only Model_Data
Rufinus
I tried it but "Class 'Model_Data' not found in ....IndexController.php on line xx.by the way thank you very much.
Dumindu
if all others fail (which shouldnt normaly) you always can extend your include path: includePaths.model = APPLICATION_PATH "models" (if APPLICATION_PATH points to demo1/application/)
Rufinus
thank you very much for still with me.I tried it also in the beginning,nothing's changed.I'm using Zend Server CE (PHP 5.3) with Win7,don't know Zend_Tool perfectly worked in this environment or I have missed sth to add.Also I run and test the Jeroen Keppens' modular application but it worked. sth wrong with my app.Thanks again
Dumindu
+1  A: 

You need to setup a resource Autoloader in your Bootstrap, something like this:

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

     return $autoloader;
}

With that, Zend can load the modules in your application, and just not models, but DbTable, Forms, Plugins, etc.

Chris
Thank you very much.I tried it but nothing's changed.I think sth wrong in my app.thanks again
Dumindu
A: 

What version of ZF do you have? I did the quickstart and It worked perfectly

curro
Yes,It's must be worked.Zend Server CE (PHP 5.3)Zend Framework Version 1.9.5.I think it's a problem of my code or the system..Thanks
Dumindu