Namespaces, Yii::import, Path Aliases Etc.

I am not very familiar with the namespaces in PHP, so my question may be naive but here is where I’m stuck :

  • in config/main_dev.php (the actual configuration file), I define a path alias hLib and I set the directory as imported :

Yii::setPathOfAlias('hLib', dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendors' . DIRECTORY_SEPARATOR . 'hLib');

return array(

    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',

    // autoloading model and component classes

    'import' => array(

        'application.components.*',

        'application.models.*',

        // ...

        'hLib.*',

    ),

    // etc.

);

then I attache a DeleteCascadeBehavior to a model :


    public function behaviors() {

        Yii::import('hLib.behaviors.DeleteCascadeBehavior');

        return array(

            // ...

            'DeleteCascadeBehavior' => array(

                'class' => 'hLib\behaviors\DeleteCascadeBehavior',

                'processRelations' => array('comments'),

            ),

        );

    }



The class is namespaced :


namespace hLib\behaviors;

class DeleteCascadeBehavior extends \CActiveRecordBehavior {

   // ...

}



In the afterDelete() method, there is a call to a method defined in hLib/h.php.

This file should have been imported due to the ‘import’ settings of the configuration file but any delete on a model objet throws a PHP error :

Moreover, if I try to manually import the missing file by adding this line in the DeleteCascadeBehavior.php file :


Yii::import('application.vendors.hLib.h');

that’s the Yii.php file which misses :

Obviously, I’m missing some point with namespaces and/or possible conflicts with pathAliases in Yii.

Any insights are welcome !