creating admin [backend]

my directory looks something like this:




cache

config/

       main.php

protected/

          commands/

          components/

          controllers/

          extensions/

          messages/

          models/

          runtime/

          yiic[text file]

          yiic.bat

          yiic.php

runtime/

themes/

index.php


admin/

     cache/

     config/

            main.php

     index.php

     protected/

               components/

               controllers/

               models/

               views/

     runtime/



is this valid? cause i want to access admin via url in this rule [www.example.com/admin]

You should place your admin folder as a module in protected/modules/admin… Next you will be able to call your website like yoursite.com/index.php?r=admin/controller/action. After managing friendly urls you can easily manage to display your url as yoursite.com/admin For more info on modules please navigate here http://www.yiiframework.com/doc/guide/basics.module

hope this helps.

thanks… hmmm… i stayed on the current directories of my files cause i don’t see any errors showing out of it…i can access admin via url [mysite.com/admin but not mysite.com/index.php/admin] and it’s fully functional already

may i know what’s with putting it in a module that makes people say the same thing to me? :D it’s a bit funny… ;D

Accessing it via mysite.com/admin is going direct to the admin files. Trying to use mysite.com/index.php/admin is using the Yii Framework routing system. The framework is built to route paths to modules/controllers/actions, which is why you should build it as an admin module. It will remain suitably encapsulated but will fit within the framework as it was designed to work. I would recommend moving it into a module, it will make maintenance easier in the long run.

oh okay… so what do i do? generate the whole admin section from scratch? since i have one already outside as i stated before…

you can use Gii to create the module. Please see the details in the yii-guide-1.1.4.pdf

I’ve made admin functionality in other way.

I have an AdminController.php which cares about authentification of admin user.

And in every controller I have added an access rules:

‘actions’=>array(‘admin’, ‘create’, ‘update’, ‘delete’),

‘users’=>array(‘admin’)

So they can’t be used only for admin user. Also I use other layout for admin actions.

So I don’t need to create any other modules for admin :)

Hope this helps.

Can you show us how did you do that???

Thanks… :)

The difference is that your admin panel is simply a second full WebApplication. It has its own models, controllers, views, components and so on. You can switch user between those apps only by generating proper URLs and cannot share data on server side. If you create admin panel as a module you can share data models, components and so on with controllers visible to public. In your solution you have to maintain copies of models and compoinents in both application or do some hacks that are not very pretty in programming style meaning.

If your solution is fine for you - good. You do not have to listen to those who suggest writing module, however they are right that this would be much prettier :)

As I went though the post I found that admin should be created inside protected/modules, i.e. it should be treated as a module. My question is that, is there any flaw if we create admin outside of protected folder as mentioned by Kael in his first post?? It, too has it’s own protected folder with its’ associated directory and files.

I do like the suggestion from bettor