Welcome Guest, Not a member yet? Register   Sign In
Again. Controller in Sub-folders (new way?)
#1

[eluser]Ignacio[/eluser]
I'm testing this on 1.5.4

routes.php:
Code:
$route['default_controller'] = "main/main";
$route['scaffolding_trigger'] = "";
$route['privacy'] = "privacy/privacy";
$route['privacy/other'] = "privacy/privacy/other";

folders:
Code:
application/controllers/main/main.php
application/controllers/privacy/privacy.php

views:
Code:
application/views/main/main.php
application/views/privacy/privacy.php
application/views/privacy/other.php

application/controllers/privacy/privacy.php:
Code:
<?php

class Privacy extends Controller {

    function index() {
        $this->load->view('privacy/privacy');
    }

    function other() {
        $this->load->view('privacy/other');
    }

}
?>

Ok... there's all my code, and works fine using this:
Code:
site.com
site.com/privacy
site.com/privacy/other

Yes! Great, works like I want... BUT! look again my routes file..., and imagine 500 pages on my site..., I can't write routes pages by pages, I need an automatic router.

I use http://code.google.com/p/enginemvc/ for a while, but is very small, I need something like CI, but don't have the features like I want. I need some help with this issue.

Thanks!
#2

[eluser]tonanbarbarian[/eluser]
Have you tried this without the routes... because the loader will search in a single depth sub folder for a matching controller
The only time we have found an issue is if you want more than 1 sub folder depth
Code:
application/controllers/main/admin/admin.php
application/controllers/main/admin/user.php
will not work.

Or if you try to do something tricky like
Code:
application/controllers/main.php
application/controllers/main/admin.php
will also not work. This is because you have a controller at the root level the same name as a sub folder

but just to have
Code:
application/controllers/main/main.php
application/controllers/privacy/privacy.php
working requires no effort

It is also unclear from your example why you are putting the controllers into sub folders. I assume there are going to be multiple controllers under the main sub folder and also under the privacy subfolder.
If not then just do not use subfolders.
#3

[eluser]Ignacio[/eluser]
First of all, BIG thanks for your response tonanbarbarian.
You right, I don't need controllers in folder, in fact I don't use them in folders in my others MVC system, hehehe.

just:
Code:
application/controllers/main.php
application/controllers/privacy.php

Works fine now with just that. Maybe I wil need a solution in a few days for doing something like this:

Code:
application/controllers/admin/main.php
application/controllers/main.php
application/controllers/privacy.php

Or start doing something like this too is fine:

Code:
application/controllers/admin/main.php
application/controllers/public/main.php
application/controllers/public/privacy.php

I don't like the modular separation for now. And yes, this data was just examples, I'm making a strong base for doing a social web site, that need a lot of files, folders and that kind of stuff.

Thanks again pal, sorry about my poor english, I'm from Argentina.

Thanks.
#4

[eluser]tonanbarbarian[/eluser]
Both of the last 2 example you give should be possible without any modification or routes
#5

[eluser]Ignacio[/eluser]
I know, but I don't want URL like this: site.com/public/privacy, maybe with .htaccess I can fix that, URL for the admin site.com/admin/privacy is fine.
#6

[eluser]tonanbarbarian[/eluser]
so then do not put any of your public controller in a subfolder
do something like the following
Code:
application/controllers/admin/main.php
application/controllers/main.php
application/controllers/privacy.php

I do this all the time.
Usually the only sub folder I have in the controllers is an admin sub folder that contains admin versions of all of the root controllers
#7

[eluser]Ignacio[/eluser]
yes, is a good solution, thanks, I'm working exactly like that now, thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB