dongtan7998 2014-06-08 03:48
浏览 50
已采纳

Yii别名不在我的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/../..

my Global class looks like this

class Globals {

         /* 
          * Check if user is an admin
          */ 
         public static function isAdmin() 
         {
          $testId = Yii::app()->user->id;
          $role = User::model()->findByPk($testId);

          return ($role['role'] == 1) ? true : false;
        }
}

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

  • 写回答

2条回答 默认 最新

  • dtgsl60240 2014-06-09 07:13
    关注

    figured it out. i had duplicate global classes in my common.components. and frontend.components. folders. silly me

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 web课程,怎么做啊😭没好好听课 根本不知道怎么下手
  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥40 matlab简单代码修改补充
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败
  • ¥15 数据结构中的数组地址问题
  • ¥15 maya的mel里,怎样先选择模型A,然后利用mel脚本自动选择有相同名字的模型B呢。
  • ¥15 Python题,根本不会啊
  • ¥15 会会信号与系统和python的来
  • ¥15 关于#python#的问题
  • ¥20 oracle RAC 怎么配置啊,配置