Yii Alias Not Working In My Main.php

I’m trying to create a site alias in my frontend/config/main.php but it doesn’t seem to import all the classes from my common/components/

here is my file structure


backend/

    common/

        components/

            Globals.php

        config/

            params.php

            params-local.php

        lib/

            yii/

        migrations/

        models/

            Comment.php

            Extension.php

            ...

    console/

        commands/

            SitemapCommand.php

            ...

        config/

            main.php

            main-local.php

            params.php

            params-local.php

        runtime/

        yiic.php

    frontend/

        components/

        config/

            main.php

            main-local.php

            params.php

            params-local.php

        controllers/

            SiteController.php

            ...

        lib/

        models/ 

            ContactForm.php

            SearchForm.php      

        runtime/

        views/

            layouts/

            site/

        www/

            assets/

            css/

            js/

            index.php

    yiic

    yiic.bat

this is what i have so far


$root=dirname(__FILE__).'/../..';


//define a path alias, site

Yii::setPathOfAlias('site',$root);


//merging together our frontend params with our common application params

$params=array_merge(

    require($root.'/common/config/params.php'),

    require($root.'/frontend/config/params.php')

);


return array(

    'name'=>'site name',


    'basePath'=>$root.'/frontend',


    // application-level parameters that can be accessed

    // using Yii::app()->params['paramName']

    'params'=>$params,


    // preloading 'app' component in frontend/extensions

    'preload'=>array('log','app'),


    // auto loading model and component classes from this application and our common application

    'import'=>array(

        'site.common.components.*',

        'site.common.models.*',

        'site.common.extensions.mailer.components.*',

        'application.components.*',

        'application.models.*',

    ),

         .......

);

everything using the site alias isn’t loaded here. When i call Globals::isAdmin(); in my footer.php, i get an error.


Fatal error: Call to undefined method Globals::isAdmin() in /Library/WebServer/Documents/dev/frontend/views/layouts/footer.php on line 81

my $root is set too


/Library/WebServer/Documents/dev/frontend/config/../..

Any idea what i’m missing or doing wrong? Thanks

Hi,

Try to find out which php file is used, for example put this code to the "dev/frontend/views/layouts/footer.php":




<?php

$reflection = new ReflectionClass('Globals');

var_dump( $reflection->getFileName() );

?>



if the dumped path is correct check the php code in the file (typo etc.)