This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Extensions » Add rules to autoload

Add rules to autoload

Add rules to autoload

Tuesday 14 June 2011 10:43:22 am - 4 replies

Hi there,

I would like to know if it is possible to add rules to autoload through ez extensions without having to alter /autoload.php .

My problem is that I have to include an extra library to read some xls files.

It works well outside of ezpublish. But to integrate it I have to add some things in the beginning :

$path = './Classes/';
    set_include_path(get_include_path() . PATH_SEPARATOR . $path);
    function __autoload($classe)
        $fichier = str_replace
             '_',           # Caractère à remplacer.
             DIRECTORY_SEPARATOR, # Caractère de remplacement.
             $classe              # Cible du remplacement.
           ) . '.php' ;
        require_once($fichier) ; # Chargement de la classe.
    // Because the name of the classes is made of the full path to the class file
    // ex. : $objet = new PHPExcel_Reader_Excel5();

Tuesday 14 June 2011 10:50:52 am

Hi Damien

Yes, this is possible, but not inside extensions. You will need to alter your config.php.

Here's an extract from config.php-RECOMMENDED :

   It is also possible to push a custom autoload method to the autoload
   function stack. Remember to check for class prefixes in such a method, if it
   will not serve classes from eZ Publish and eZ Components.
   Here is an example code snippet to be placed right in this file, in the case
   you would be using your custom Foo framework, in which all PHP classes would be
   prefixed by 'Foo' :
       ini_set( 'include_path', ini_get( 'include_path' ). ':/usr/lib/FooFramework/' );
       require 'Foo/ClassLoader.php';
       function fooAutoload( $className )
          if ( 'Foo' == substr( $className, 0, 3 ) )
              FooClassLoader::loadClass( $className );
       spl_autoload_register( 'fooAutoload' );

Modified on Tuesday 14 June 2011 10:52:49 am by Jérôme Vieilledent

Tuesday 14 June 2011 10:58:18 am

Thanks Jérôme.

It will save my day happy.gif Emoticon

Tuesday 14 June 2011 4:32:10 pm

Hi Damien, in fact you can use external libraries without altering config.php, see here:

Wednesday 15 June 2011 1:58:25 pm

Hi Damien, in fact you can use external libraries without altering config.php, see here:

It looks interesting too. I'll look at this when I'll have some time



You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from