CodeIgniter Forums
How to use CI with multiple folders - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How to use CI with multiple folders (/showthread.php?tid=27262)

Pages: 1 2


How to use CI with multiple folders - El Forum - 02-05-2010

[eluser]Mareshal[/eluser]
A friend made me a challenge. Access a controller inside a folder tree.

For example. I have /controllers/folder_1/folder_2/folder_3/controller.php

and I want in my browser example.com/folder_1/folder_2/folder_3/controller/function_name

is this possbile?


How to use CI with multiple folders - El Forum - 02-05-2010

[eluser]Michael Wales[/eluser]
Don't use folders to alter your URL, use URI Routing.


How to use CI with multiple folders - El Forum - 02-05-2010

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-guide/general/controllers.html

Quote:Organizing Your Controllers into Sub-folders

If you are building a large application you might find it convenient to organize your controllers into sub-folders. CodeIgniter permits you to do this.

Simply create folders within your application/controllers directory and place your controller classes within them.

...



How to use CI with multiple folders - El Forum - 02-05-2010

[eluser]physicsdave[/eluser]
[quote author="Michael Wales" date="1265395143"]Don't use folders to alter your URL, use URI Routing.[/quote]

Agreed, I've use both methods but have found that routing is the easiest to use/maintain and is far more flexible. CI even makes it easy, for the most part you won't have to learn regular expressions if you don't want to.

Check it out:
http://ellislab.com/codeigniter/user-guide/general/routing.html


How to use CI with multiple folders - El Forum - 02-05-2010

[eluser]Mareshal[/eluser]
So, if i really want to use multilevel folder simply is not possible right?


How to use CI with multiple folders - El Forum - 02-05-2010

[eluser]Carl_A[/eluser]
Hi,

Im having a similar problem:

I have subfolders in the controllers folder. It works with a complete index.php URI however, doesnt work when I add the .htaccess file..

What I mean is:

I have -> application/controllers/admin/controller_name.php

It works when I do www.example.com/index.php/admin/controller_name,

But as soon as I add the .htaccess file,
www.example.com/admin/controller_name gives me a 'file not found' error.


My Aim: Have subfolders to organize my controllers.


Can someone help?



My .htaccess file: (with ref to this: http://codeigniter.com/wiki/mod_rewrite/ )

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>



How to use CI with multiple folders - El Forum - 02-06-2010

[eluser]Mareshal[/eluser]
1. if you don't have an index() function in your controller, call another function from your controller see if it works
2. RewriteCond %{REQUEST_URI} ^system.* don't have this in my htaccess


How to use CI with multiple folders - El Forum - 02-06-2010

[eluser]Carl_A[/eluser]
1. I do have an index() function.. and strangely everything works as long as I dont put the .htaccess file and use a complete link with index.php ( www.example.com/index.php/admin/controller_name )
It works perfectly with these links.

2. I followed the article here : http://codeigniter.com/wiki/mod_rewrite/

Every other controller (outside the subfolder) works perfectly with both
www.example.com/index.php/controller_1

And
www.example.com/controller_1

Its just the ones with the subfolder thats causing a problem.


How to use CI with multiple folders - El Forum - 02-09-2010

[eluser]Carl_A[/eluser]
Bump... anyone help?


How to use CI with multiple folders - El Forum - 02-24-2010

[eluser]Carl_A[/eluser]
Someone please help me..