views:

242

answers:

1

Read the comments in the code for a description:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function __construct($configSection){
        $rootDir = dirname(dirname(__FILE__));
        define('ROOT_DIR',$rootDir);

        set_include_path(get_include_path()
        . PATH_SEPARATOR . ROOT_DIR . '/library/'
        . PATH_SEPARATOR . ROOT_DIR .
        'application/models'
        );

        //PROBLEM LIES HERE, BEWARE OF DRAGONS.
        //Using this, I receive a deprecated warning.
        include 'Zend/Loader.php';
        Zend_Loader::registerAutoload();        

        //Using this, I recieve an error that autoload() has missing arguments.     
        //Zend_Loader_Autoloader::autoload();       

        //Load the configuration file.
        Zend_Registry::set('configSection', $configSection);
        $config = new Zend_Config_Ini(ROOT_DIR . '/application/config.ini',$configSection);

        Zend_Registry::set('config',$config);
        date_default_timezone_set($config->date_default_timezone);

        //Database configuration settings go here. :)
        $db = Zend_Db::factory($config->db);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        Zend_Registry::set('db',$db);
    }

    public function configureFrontController(){
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->setControllerDirectory(ROOT_DIR . '/application/controllers');
    }

    public function runApp(){
        $this->configureFrontController();

        //Runs the Zend application. :)
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->dispath();
    }
}

I'm trying to follow a tutorial that wants me to configure my Zend app to use the autoloading functions that it offers.

When using the registerAutoLoad() method, I receive a deprecated warning and it tells me to use another method, the one below it in my code.

What can I do?

Edit: Why I was using the deprecated method:

One less than ideal aspect of the bootstrap file in the original Hello World is that there are a lot of Zend_Loader::loadClass() calls to load up the classes we need before we use them.

In larger applications, there are even more classes in use, resulting in clutter throughout the application just to ensure that the right classes are included at the right time.

For our Places website, we use PHP’s __autoload() functionality so that PHP will automatically load our classes for us. PHP5 introduced the __autoload() magic function that is called whenever you try to instantiate a class that hasn’t yet been defined.

The Zend_Loader class has a special registerAutoload() method specifically for use with __autoload(), as shown in listing 3.1 b. This method will automatically use PHP5’s Standard PHP Library (SPL) spl_autoload_register() function so that multiple autoloaders can be used.

After Zend_Loader::registerAutoload() has been called, whenever a class is instantiated that has not yet been defined, the file containing the class is included. This solves the problem of Zend_Loader::loadClass() clutter and ensures that only the needed files are loaded for any given request.

+3  A: 

Because Autoloading was changed in ZF1.8 you should replace

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

with

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('App_');

or use the fallback autoloader with

$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);

Depending on the age of your tutorial, I suggest checking out the tutorial for the recent ZF1.10 at Rob Allen's blog as well.

Gordon
This is the correct answer!
David Caunt