admin area as a module or sub controller folder?


I’m wondering which option is better; create a normal folder under controllers folder or create a module called ‘admin’ with submodules in it, such as ‘comment’ and ‘user’, and why?


For added security, I tend to go for a separate application, using the same database. :)

I’ve tried admin module, but it leads to very spaghetti code if you’re not careful…

I completely agree.

I agree with jacmoe and chris that making the admin page a separate application is the best option. But if you are to choose between making it a controller or a module, my vote will be for the module.

If you create a separate application, how do you deal with having to recreate all the models/components/extensions? Do you just copy every single thing over?

i prefer to use module than separate application :lol:

  1. for shared classes (under components or models dir), you don’t need to do additional things ;

  2. if you want access some front functionality ,it’s easy . for example if you want access some route which direct to front-end . just use $this->createUrl(‘someModule/someController/someActionId’); or runController($someRoute); if you use a separate app as admin you will meet some problem ,because the front-end and the back-end have different entry script ( index.php for front or admin.php for backend).

for short : if you have nothing to share or nothing to interoperate between front-end and backend just use a separate app(even use separate app you can share some config see Separation of admin controllers from public controllers ,). if you have more things to share or want access to front-end just use module . never use adminController ,when more and more functionality involved you will get a terrible fat class .

no need just share the config file , see this wike written by qiang :Organize directories for applications with front-end and back-end


@mbi: Same reasons and jacmoe mentioned, having the administration area as a module leads to poor quality of code in most cases. I actually have a site in production with this solution and I can tell you that it’s not a good solution. I’d rather organize the application in common/frontend/backend.

Here’s a useful link:

The directory structure of the Yii project site

How do you manage creating front end urls from the backend app ?

Currently i am doing same thing, common/front/admin but this is the issue that bothers me, generating frontend url from backend(without the need to pass the front rules into the common config so that the backend app access them).

@jacmoe, @chris83

what means poor quality of code in most cases by example?

however, the more i think about it, the more i like this approach

Thank you very much for your inputs. Personally, I will go with Qiang’s suggested method.

That’s not an easy question. :P

Sometimes a simple ‘administration’ action in the site controller is all you need. The rest of the administration is dealt with access control rules and enforced in the admin actions in the various controllers. No need to create a separate admin controller, a module or even a different application.

In one application of mine I ended up having an admin module which mainly consists of links to actions in the main app.

Only one or two actions were implemented…

Could have been put in the site controller or a settings controller instead…

Really need to refactor that!

Sometimes, especially when you have a really extended administration interface, with a clearly defined set of functions, it makes sense to create a separate application because it allows you to create a dedicated admin theme/interface, with separate login and access rules - maybe even htpassword and/or SSL ?

It just feels cleaner to me. :)

You can do this using modules, but…

Since administration is performed on the rest of the application, it really can’t be a self-contained unit.

That’s the main problem, IMO.

The only way it can be a self-contained unit is to self-contain it: a new app, using the same database.

This is an interesting alternative:


Courtesy of Andy.

Not sure how it performs, though.

yes, now I fully agree with you :slight_smile:

so this is now good for me:

the admin-area of an application is a whole separated application with its own userIdentity, modules, controllers and actions

there is a frontend under and a backend under