views:

746

answers:

3

Hi, I'm trying to develop a little base CMS with CodeIgniter for my own use on projects but got stuck on this. Also, I'm very new to CI, but got some years with ZF and OOP PHP.

First of all let me show you my file structure:

  • index.php (frontend bootstrap)
  • backend.php (backend bootstrap)
  • .htaccess
  • system ( CI core )
    • application
      • backend
        • [...] MVC related files and folders (config, controllers, models, views...)
      • frontend
        • [...] MVC related files and folders (config, controllers, models, views...)
    • codeigniter
    • [...] (cache, database, scaffolding...)

Ok. I can get to work the index.php or backend.php routing with an .htaccess, but can't get it to work with both. Here's the .htaccess code:

RewriteEngine on
RewriteBase /

# Hide the application and system directories by redirecting the request to index.php (and throwing a 404 error)
RewriteRule ^(application|system|\.svn) index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Well, what I need is the following:

  • www.domain.com/backend/controller/action/parameters (backend.php routing)
  • www.domain.com/controller/action/parameters (index.php routing)

Hope I explained well.

Can anyone help, please? :)

Best regards.

A: 

Basically you want to run two CodeIgniter applications side by side, one in the root and one in backend/. There are a few ways to do this, but the simplest is to add a rewrite rule for your second instance (removing the Last flag):

RewriteRule ^backend/(.*)$ /backend/index.php/$1 [QSA]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Bruce Alderson
Doing this way, if I call "http://localhost/ci_cms/backend" i get a 404 response over this url "/index.php/backend".It must point to the backend.php itself, like the rest of request goes to index.php.Is my /system/application/ tree structure correct?:)
Raul Illana
The URI for the backend would be similar to any CI route, except with /backend/ in it: `site.com/backend/route/parameter`.
Bruce Alderson
As for structure, for this suggestion to work you would need 2 copies of CI (which I don't normally do, but have prototyped in the past), one copy in each root. The HMVC approach is what I ended up using in most of my projects, as maintaining one CI install is much simpler.
Bruce Alderson
I'll try HMVC this weekend... Stay tunned, I'll surely need help. :P
Raul Illana
+1  A: 

After some more searching, I've found a very nice article documenting how to do what I need. It also explains the 3 ways to backend/frontend in CI:

  • separate applications
  • sub-directories
  • HMVC (Hierarchical Model View Controller)

HMVC fits my needs perfectly, but i'll give a try to sub-directories first. :)

Raul Illana
A: 

But doing this I cant access my css/images etc plz help????

Sameer