CodeIgniter Forums
Controllers and subfolders - 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: Controllers and subfolders (/thread-43417.html)



Controllers and subfolders - El Forum - 07-10-2011

[eluser]Unknown[/eluser]
I've searched the net and found nothing about this for v2.0.2, and the ways I found for v1.x are pretty hacky too. I came up with the following, which seems to kind of work:

Code:
function _remap( $method ) {
        if ( method_exists( $this, $method ) ) {
            $this->$method();
            return;
        } else {
            $p = str_replace('.php', '', __FILE__) . '/';
            if ( file_exists( $p . $method . EXT ) ) {
                include_once( 'admin/' . $method . EXT );
                $obj = new $method();
                $f = $this->uri->segment( 3 );
                if ( $f == 'list' ) { $f = 'show'; }
                if ( method_exists( $obj, $f ) ) {
                    $obj->$f();
                    return;
                }
            }
        }

In my case, the Controller class is 'Admin', hence the hardcoded 'admin/' directory.

However, when doing this, it seems that the autoloaded session's library is not available. Is there an easy step that I'm missing? Or is there another way to make subfolders and controllers work well together?

Thanks.


Controllers and subfolders - El Forum - 07-12-2011

[eluser]Eric Barnes[/eluser]
I am not sure I follow. How many subfolders you want? Just one or ten deep?