Common Controllers For Backend And Frontend

Hello,

I am creating a project using Yii framework.

I have successfully separated backend and frontend following this article.

Also I am having two different login forms for backend and frontend but using same UserIdentity Component for authentication at both ends.

I want to know how I can use same controllers for both backend and frontend (using this directory structure).

The reason I want to have common controllers is that there’s only admin and delete action to which front users have no access. So having two copies of same controllers in two different places seems to be redundant.

plz help.

Edit: m following this directory structure


root

|__protected

|  |__config

|  |  |__front.php

|  |  |__back.php

|  |  |__main.php

|  |

|  |__controllers

|  |  |__back

|  |  |__front

|  |

|  |__views

|  |  |__back

|  |  |  |__layout

|  |  |  |__site

|  |  |

|  |  |__front

|  |     |__layout

|  |     |__site

|  |

|  |__models

|

|__index.php

|__admin.php



urlmanager in protected/config/front.php


'urlManager'=>array(

	'urlFormat'=>'path',

	'showScriptName'=>false,

	'rules'=>array(

		// a standard rule mapping '/' to 'site/index' action

		'' => 'site/index',


		// a standard rule mapping '/login' to 'site/login', and so on

		'<action:(login|logout|about)>' => 'site/<action>',

                '<controller:\w+>/<id:\d+>'=>'<controller>/view',

                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

	),

),

urlmanager in protected/config/back.php


'urlManager'=>array(

	'urlFormat'=>'path',

	'showScriptName'=>false,

	'rules'=>array(

		// a standard rule mapping '/' to 'site/index' action

		'admin' => 'site/index',

		// a standard rule mapping '/login' to 'site/login', and so on

		'admin/<action:(login|logout|about)>' => 'site/<action>',

		'admin/<_c>'=>'<_c>',

		'admin/<_c>/<_a>'=>'<_c>/<_a>',

	),

),

so that I can access backend using this ‘sitename/admin/user/create’ etc.

Thanks,

Uttara

i think you can apply in defaulaccess rules in your controller


public function defaultAccessRules() {

        return array(

            array('allow', // allow all users to perform 'index' and 'view' actions

                'actions' => array('create', 'update', 'admin', 'delete', 'change'),

                'users' => array('admin'),

            ),

            array('allow', // allow authenticated user to perform 'create' and 'update' actions

                'actions' => array('create'),

                'users' => array('user'),

            ),

        );

    }

more help…

http://www.yiiframework.com/wiki/169/configuring-controller-access-rules-to-default-deny/