user1613887
user1613887

Reputation: 23

Yii front and backend common structure and access to link and htaccess settings

I m beginner in yii

I have created one structure to handle files for frontend and backend so that common files can be used for both and different files form their folder


framework/ (This folder will contain all yii framework core folders and files) assets/ js/

frontend/

common/

backend/

api

images/ storage/

protected/ components/ config

main.php (DB, emails, etc...)

controllers/

frontend/

backend/

views/

frontend/

backend/

models/ extensions/ modules/

runtime/ index.php .htaccess


this structure is created for booking application. Some common files are shared between them it will be there in controller/ and views/ and differnrt file will be in controller/frontend/ and controller/backend/

Example I have files in both folder as below

controller/ SiteController.php

Frontend/SiteController.php

Backend/SiteController.php

views/ layouts/

Frontend/layouts

Backend/layouts

Now the question is how can i set .htaccess so that when i write http://myapp.com/index.php --> will access all files for frontend and http://myapp.com/backend/inex.php --> will access backend files (beckend views and controller)

Upvotes: 2

Views: 1472

Answers (1)

Alexander Palamarchuk
Alexander Palamarchuk

Reputation: 879

Copy .htaccess and index.php to [/backend/] folder. Then in new index.php change path to the config, different to main one. E.g.

$config=dirname(__FILE__).'/../../'.YII_PROTECTED.'/config/admin.production.php';

And create own config for the backend independently.

So you can use any common views, controllers or models, but most importantly to control it with UrlManager. Here's an example from my personal site (you can test its URL logic externally):

Frontend:

    'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'urlSuffix' => '/',
        'rules'=>array(
            '<controller:profile>/' => '<controller>/index/',
            '<controller:profile>/<action:cv>/<project:\w+>' => '<controller>/portfolio/',
            '<controller:profile>/<action>' => '<controller>/<action>/',
            '<controller:blog>/' => '<controller>/index/',
            '<controller:blog>/<postID:[0-9]+>.html' => '<controller>/post/',
        ),
    ),

Backend:

    'rules'=>array(
        '/' => 'autoadmin/default/index',
        '<controller:\w+>' => 'autoadmin/<controller>/index',
        '<controller:\w+>/<action:\w+>' => 'autoadmin/<controller>/<action>',
    ),

The Backend looks into AutoAdmin CMS, which executes as a module.

The both use the same file structure, but each can use anything common (most probably it would be models).

Upvotes: 0

Related Questions