0

Can anybody tell me that how can i call controller inside a sub-folders. I am trying to call controller at third level of controller folder and i tried some example through googling but that all are not working. For Example :

http://localhost/project/index.php?/folder1/folder2/folder3/controller.php

1 Answers1

1

Create file inside applicaiton/core folder with the name MY_Router.php and place below code inside it and it will work :--

Note : This solution is for Codeigniter 2.2.0

<?php


Class MY_Router extends CI_Router
{
    Function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            return $segments;
        }

        if (is_dir(APPPATH.'controllers/'.$segments[0]))
        {
            $this->set_directory($segments[0]);
            $segments = array_slice($segments, 1);

            /* ----------- ADDED CODE ------------ */

            while(count($segments) > 0 && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]))
            {
                // Set the directory and remove it from the segment array
            $this->set_directory($this->directory . $segments[0]);
            $segments = array_slice($segments, 1);
            }

            /* ----------- END ------------ */

            if (count($segments) > 0)
            {
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
                {
                    show_404($this->fetch_directory().$segments[0]);
                }
            }
            else
            {
                $this->set_class($this->default_controller);
                $this->set_method('index');

                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                {
                    $this->directory = '';
                    return array();
                }

            }

            return $segments;
        }

        show_404($segments[0]);
    }
}

?>