views:

64

answers:

1

I have a simple ZF application (no modules) which works fine when I require classes before I use them. However, I'd like to use the ZF autoloader to load them automatically (which I assumed was default behaviour).

How would I go about doing this? I'm a bit confused by the new(ish) Zend_Application way of doing things. My directory structure is the standard one:

application/
  controllers/
  models/
  views/        
  scripts/
    Bootstrap.php

For example removing the require in this method:

class HomeController extends Zend_Controller_Action {
    public function indexAction() {
        $tasks = array();

        //require 'models/Task.php';
        $tasks[] = new Application_Model_Task(array(...));
    }
}
+2  A: 

If you use Zend Frame Version 1.8 (+) put this in your Bootstrap.php:

   /**
     * Initialize the autoloader
     *
     * @return Zend_Application_Module_Autoloader
     */
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
                'namespace' => 'My',
                'basePath'  => dirname(__FILE__),
        ));

        return $autoloader;
    }

And now try :

$model = new My_Model_Task();
ArneRie
I replaced My with Application and it worked perfectly - thanks!
Ross
fine! you can also replace "Application" by " " , and use: new Model_Task()
ArneRie