Yii::registerAutoloader must be placed in index.php file?

I’ve come across one example of implementing [color=#808080][font=Menlo, Consolas,][color=green][size=2]Yii[/size][/color][color=gray][size=2]::[/size][/color][color=green][size=2]registerAutoloader [/size][/color][/font][/color]at this address http://www.yiiframework.com/extension/zendautoloader

But this tells that I should put in index.php, but what about console apps?

Isn’t there a global place where I should include my custom autoloader to be available for all web/console etc apps?

In that case, put it in your console applications main script - like ‘console.php’.

It looks like it has to happen before app->run, so you can’t really put it elsewhere.

Isn’t there a more general way of doing this? To include only at one place and to be available for all kind of instances?

By including twice on index and console it could leave to future problems, loosing syncronization.

You could just place that Zen autoload code in a separate php file and use ‘require’ - problem solved. :)

I’ve set up a basic component to do the job e.g.




require_once 'Zend/Loader/Autoloader.php';


class ResourceLoader extends CApplicationComponent

{

    public function init()

    {

        \Yii::registerAutoloader(array('Zend_Loader_Autoloader', 'autoload'));

    }

}



config file (main.php)




Yii::setPathOfAlias('vendor', realpath(dirname(__FILE__).'/../../vendors/'));


return array(

    //..

    'import' => array(

	'application.models.*',

	'application.components.*',

        'vendor.*',

    ),

    'preload'=> array('loader'), // preload the resource loader


    //..

    'components' => array(

        'loader' => array('class' => 'ResourceLoader'),



this works in test but if I want it to work in console then I’d have to add some config to config/console.php

N.B. I had to add a setPathOfAlias as I have put the Zend code in a directory outside of Yii.