multi-level subfolders for controllers for 1.7.1 |
[eluser]Damien K.[/eluser]
Just want to throw it out to the community yet another multi-level subfolders controller extension. This is for 1.7.1. HTH, Damien K. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]krzycho[/eluser]
Very nice and elegant Since one could pass URI without controller name (assuming that default controller should be loaded), you should check if $segments array is not empty: Code: } while ((is_dir(APPPATH.'controllers/'.$dir .'/'.$segments[0])) && (!empty($segments)));
[eluser]g_montel[/eluser]
Hello It looks like this hack is not compatible with CI 1.7.3 as it used to be in 1.7.2 Any idea on how to get multi level controllers in 1.7.3 ? Thanks in advance geoffroy
[eluser]Unknown[/eluser]
I've moved to code igniter 2.0.0 and this alternate router stopped working. After some debug i've found that in this new version they've updated set_directory function in the core Router. The new version replaces all the / in the directory and replaces with "" function set_directory($dir) { $this->directory = str_replace(array('/', '.'), '', $dir).'/'; } This way the directory we're trying to use becomes a complete different one. In the case I was working on "backoffice/system" became "backofficesystem"... I've just updated my_router and added a new/old version of set_directory // Replaces new set_directory function in code igniter 2.0.0 with version 1.7.2 function set_directory($dir) { $this->directory = $dir.'/'; } Now, its working fine again
[eluser]xerobytez[/eluser]
Awesome snippet, this is exactly what I need. But I'm getting this error when trying to use it. A PHP Error was encountered Severity: Notice Message: Undefined offset: 0 Filename: core/MY_Router.php Line Number: 43 Line 43: Code: } while (is_dir(APPPATH . 'controllers/' . $dir . '/' . $segments[0])); Anyone have any ideas? Trying to use this with CodeIgniter 2.0 Thanks
[eluser]ChrisHJ[/eluser]
[quote author="xerobytez" date="1298060643"]Awesome snippet, this is exactly what I need. But I'm getting this error when trying to use it. A PHP Error was encountered Severity: Notice Message: Undefined offset: 0 Filename: core/MY_Router.php Line Number: 43 Line 43: Code: } while (is_dir(APPPATH . 'controllers/' . $dir . '/' . $segments[0])); Anyone have any ideas? Trying to use this with CodeIgniter 2.0 Thanks[/quote] Just add Code: if(!empty($segments)) {code}
[eluser]erikstraub[/eluser]
If you change the do/while loop to: Code: do and then move the file_exists if statement below the is_dir if statement, you will be able to have a file structure where a controller and directory of the same name can exist in the controllers directory. Like this: Code: controllers/example.php
[eluser]fivefinger-bd[/eluser]
Hello Very nice post. I have tested the code for 2.0.0 it works fine. But fetching some problem when making mobile interface using jquery mobile. And the problem occurs when you browse with an Android. The problem is it does't load the css, js etc. Any idea?
[eluser]fivefinger-bd[/eluser]
[quote author="fivefinger-bd" date="1310504107"]Hello Very nice post. I have tested the code for 2.0.0 it works fine. But fetching some problem when making mobile interface using jquery mobile. And the problem occurs when you browse with an Android. The problem is it does't load the css, js etc. Any idea?[/quote] Sorry my mistake. Problem was Android doesnot support http://localhost It supports http://10.0.2.2
[eluser]riwakawd[/eluser]
[quote author="Damien K." date="1253243847"]Just want to throw it out to the community yet another multi-level subfolders controller extension. This is for 1.7.1. HTH, Damien K. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Anyone for latest version of CodeIgniter_2.1.4 I am trying to make default router load. $route['default_controller'] = "frontend/common/home"; |
Welcome Guest, Not a member yet? Register Sign In |