Having Common Controllers For Backend And Frontend


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 seems to be redundant.

plz help.




If controller is for admin and delete action -and- front user have no access… … Then why you want two different controller…??

You can create single controller for Admin side.

By the way you can call (Admin/Back) controller in Front using,


$xyzObj =new XyzController();


Thanks for replying

If you refer to my another post (similar edited one) ‘Common Controllers For Backend And Frontend’, my controllers are inside controllers/back and controllers/front

I am having say 10 controllers common to both end, except user controller to which front users don’t have access, thats why I don’t want to have two copies of same controllers in front and in back.

sorry but where m supposed to use this


$xyzObj =new XyzController();


say m having SalesController.php both in front and in back


Still can’t understand your requirment… We seperate directory structure to seperate our Admin and Front code.

but as you say you had most of common controllers… Its better to use different controllers for different side (Admin/Front).

If you had most part of common then i think no need to seperate side (Admin/Front).

You just have to use only one side and just differentiate files (action) permission as Admin / User.

I think you were better off following this article which also covers resources shared between front- and backend. If you need an example, have a look at clevertech’s YiiBoilerplate.