Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top