CodeIgniter Forums
CMS best practice on CI - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: CMS best practice on CI (/thread-55341.html)

Pages: 1 2

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Felipe Deitos[/eluser]
Hi, i am working for some time with CI, but i'm still a newbie...
I am trying to do a consistent CMS, so i can use it in other jobs.

I am struggling with the folder structure and url structure inside my application.

What is the best way of doing the folder and url structure?

I got a folder inside views called admin..
When the user go to /admin he will login and enter in the admin

Then lets pretend we got a news system in CMS

Should i put the views/controllers/models inside the admin files and folder?
All the url will be like /admin/news or /admin/newsadd that will be nice but at the end in the admin controller and admin model i will have like 1000012389 lines hehe...

I guess that is not nice...
But then if i put the news files outiste the admin folder, in a new folder called /news
The url it will be outside the /admin

(THAT WAS FREAKING CONFUSING i hope u guys understand what i mean)

Can someone please tell me what is the best practice, or tell me how you do that so i can compare?


CMS best practice on CI - El Forum - 10-22-2012

For frontend files you can just put them without sub-folders.

For your admin files you can put them inside /admin sub-folder

For news files you can put them inside news sub-folder

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Felipe Deitos[/eluser]
First of all thanks for the fast answer mate!

Ok i guess i understand that, but my question is, doing that ALL my functions will stay inside the admin.php(controller)? (News functions, product functions, newsletter functions...)

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Mr. Pickle[/eluser]
Just a few idea's with some different approaches:

What I always prefer in this case is to just have an extra application for the admin.
Folder structure for example like this:
-index.php (linked to admin application folder)
- index.php (linked to admin application folder)

Of course you have to want to seperate the two applications.
I can understand that certain system share so much that you better want to have them in one application.
(of course you can always use symlinks to have certain files / libraries / etc. shared)

Another way can be to have the controllers that should be behind admin-protection (username/password) to extend an Admin_Controller and normal controllers to extend directly CI_Controller or an Public_Controller in case you want to have an overall controller for your public parts.
In this Admin_Controller you can build your security.

If it's just about having clean and logical url's you can also choose to re-route the url e.g. /admin/news/add/ to any controller/method you want (e.g. /admin/news_add/)

CMS best practice on CI - El Forum - 10-22-2012

each sub-folder has class.

for admin you will have /admin/admin.php
for news you will have /news/news.php
for product you will have /product/product.php

For controllers you need to extend the My_Controller.

I think you need to read the entire documentation and learn MY_Controller and MY_Model first,
before diving into CMS thingy.

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Mr. Pickle[/eluser]
Oh, and have a look at modular extensions (HMVC), a nice way to make a module for everything (news, products, newsletters)

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Felipe Deitos[/eluser]
Guys i guess i not expressed myself well.
So i uploaded my test site and you guys can see what i have now and what i really want.
(You guys probably will not understand what is written there because its portuguese, im from brazil, sorry about my freaking bad english by the way)

This is the login page
When u login you will be redirect to: (user: test pass: [email protected] [try it])

The login system is working great (i guess hehe)

When u guys login theres only one link working click in "Banners" and then "Visualizar"...
The url now will be: (THATS PERFECT... is perfect because u really inside the admin in the url)

Like i said the url is perfect, but the files and folders not yet.


I want something like that

-----banners.php (all the banners code here)
/views(the views are okay i got a good template library)

Thats easy to do... but if i doo this the url will be wrong,edit,view)

Any idea?
I like the Mr.pickle idea to use routes but i dont even know how to use them...

Sorry about making you guys read that much hehehehehe
Thansk for your help! Cheers!

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Mr. Pickle[/eluser]
This page will give you a heads up on how to use uri routing in CI:

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Mr. Pickle[/eluser]
Just to add to last post:
Using the folder structure like you want it, makes CI not making the url's like you want to by default.
You either have to solve it by rerouting (see link in previous post) or changing your structure (e.g. different application for the admin)

Rerouting sounds the easiest if you are already this far that the news controller contains security (meaning you can not access it without being logged in)

For example, to put in your routes.php in de /config/ directory something in this direction:

$routes['admin/news/add'] = 'news/add';
$routes['admin/news/edit/(:num)'] = "news/edit/$1";

Or, if you always have the same uri structure and don't want to make all the different lines for every module and every module method:

$routes['admin/(news|products|module1|module2)/(:any)'] = '$1/$2';
$routes['admin/(news|products|module1|module2)']        = '$1';

CMS best practice on CI - El Forum - 10-22-2012

[eluser]Felipe Deitos[/eluser]
I have read about routing in the user guide, and i guess that your examples dont make what i want...
hehehe I promisse that this is my last question.

What i actually want...
When the user access news(controller)/add(function)
I want url admin/news(controller)/add(function)

So in the url it will always seems that the user is inside the admin...
There anyway of doing this?

If there is no way of doing this routing... I wanna know if i can extend one controller from another?
Because in the admin controller there is the function called is_logged
And i will use this in all the other controllers... so it will be good if i can extend the admin controller instead of writting over and over again this function in every controller.