dqwmhrxt68679 2013-05-21 01:04
浏览 56
已采纳

Yii文件夹结构和n个应用程序的全局配置

I'm building a folder structure and global configuration to allow me to create applications on Yii framework where all applications could share common codes, extensions or modules.

The idea is, each application would have the business level for that application, but, everything that can be shared between applications, we want to use as a common repository (models, extensions, widgets, etc)

For example, we want to share the Auth extension to control the system permission, but I want to 'install' Auth under the common folder instead under each application.

Below, the architecture that I would like to build:

Architecture of the applications

I found the YiiBoilerplate as something similar, but they don'y configure Yii in such way that we want to.

The folder structure desire is:

common/
    css/
    images/
    protected/
        commands/ 
        components/ 
        config/ 
        controllers/ 
        extensions/ 
        models/ 
        views/ 
Application1/
    css/
    images/
    protected/
        commands/ 
        components/ 
        config/ 
        controllers/ 
        extensions/ 
        models/ 
        views/ 

So, let's go for some points:

  1. If my user is under the application X (www.applicationx.com) and the login page is a 'common' structure I want to display to user something like this: www.applicationx.com/index.php?r=user/login.

  2. I want to be able to 'navigate' between the application folder and the common folder easily.

  3. I do not want to use Theme because I have different applications with different visual requirements and behaviors.

Any thoughts about this? Any good advices? Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongyulan6251 2013-06-06 04:37
    关注

    Well, I found some way of how to do it.

    First of all, my folders structure, looks similar as it:

    common/
        css/
        images/
        js/
        extensions/
            bootstrap/
            auth/
        protected/
            /* Yii Default directory folder*/
    Application1/
        css/
        images/
        js/
        protected/
            /* Yii Default directory folder*/
    

    Config File Under Common Folder

    return array(
        'import'=>array(
            'common.components.*',
            'common.models.*',
        ),
        'modules' => array(
            'auth',
        ),
        'components' => array(
            'authManager' => array(
                'behaviors' => array(
                    'auth' => array(
                        'class' => 'common.modules.auth.components.AuthBehavior',
                        'admins'=>array('admin', 'foo', 'bar'), 
                    ),
                ),
            ),
            'user' => array(
                'class' => 'common.modules.auth.components.AuthWebUser',
            ),
            'bootstrap'=>array(
                'class'=>'common2.extensions.bootstrap.components.Bootstrap',
            ),
        ),
    );
    

    Login

    The login is under 'common', so, to redirect to the login page, I just call the SiteController.php and I implented there the login process, giving for the user the ability to select the application that he wants to get in.

    After the login, I redirect the user to the application address:

    $this->redirect(Yii::app()->request->getBaseUrl(true) . "/../" .$App. "/" . "");
    

    Config File Under Application Folder

    under the application, the index.php file has the alias for the common directory, is the way that they can still 'talking'.

    Yii::setPathOfAlias('common', dirname(__FILE__) . $directory);
    

    If you want to do something similar and are finding hard to understand, let me know, I will put here more information, if you need to.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成