CodeIgniter Forums
CMS best practice on CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- 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?

Thanks!




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

[eluser]solid9[/eluser]
For frontend files you can just put them without sub-folders.
Code:
controller/
models/
views/

For your admin files you can put them inside /admin sub-folder
Code:
controller/admin
models/admin
views/admin

For news files you can put them inside news sub-folder
Code:
controller/news
models/news
views/news





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:

1.
What I always prefer in this case is to just have an extra application for the admin.
Folder structure for example like this:
/frontend/
/controllers/
/models/
/views/
/admin/
/controllers/
/models/
/views/
/[webroot]/
-index.php (linked to admin application folder)
/admin/
- 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)

2.
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.

3.
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

[eluser]solid9[/eluser]
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
etc...

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.

http://www.zephyr.com.br/previews/homespa/admin/login
(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])
http://www.zephyr.com.br/previews/homespa/admin

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:
http://www.zephyr.com.br/previews/homespa/admin/banners (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.

/controllers
-----admin.php
/views
-----/banners
----------admin_view.php

I want something like that


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

Thats easy to do... but if i doo this the url will be wrong

http://www.zephyr.com.br/previews/homespa/banners/do_something(add,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:
http://ellislab.com/codeigniter/user-guide/general/routing.html


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:

Code:
$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:

Code:
$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.