• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
default controller in sub dir doesnt work

#1
[eluser]the real rlee[/eluser]
Hi guys not sure this is related to this bug post about sub applications, but i\'ve found i keep getting 404\'s when i set the default_controller to a controller within a subdir. A few echo statements reveals that the class name for the default controller is not getting set properly in Routes.php - it seems to be using the controller path and not the controller name!

Router.php (line 109):
Code:
$this->set_class($this->default_controller);
// is actually setting the class to subdir/controller

And then CodeIgniter.php creates the 404 (line 158):
Code:
$class  = $RTR->fetch_class(); // is subdir/controller
$method = $RTR->fetch_method();
// does a class called \"subdir/controller\" exists - of course not!
if ( ! class_exists($class)
   OR $method == \'controller\'
   OR substr($method, 0, 1) == \'_\'
   OR in_array($method, get_class_methods(\'Controller\'), TRUE)
   )
{

#2
[eluser]the real rlee[/eluser]
Further nvesttigation seems to indicate that the CodeIgniter class calls the fetch_directory() function of the Router class, which returns the controller directory ($this->directory) which has only been initialised and not set to the specific controller path! Only later does it get set properly...

#3
[eluser]the real rlee[/eluser]
UPDATE: Seems my fix (below) doesnt quiet work when some controllers are in the controllers root dir

For the time being i\'ve added these lines of code to the Router constructor (line 92 just under where default controller is set):

Please note i havent fully tested this but seems to work for me!


Code:
// RL default_controller in subdir patch
        if (strrpos($this->default_controller, \'/\')) {
            $this->directory = substr( $this->default_controller, 0, strrpos($this->default_controller, \'/\')+1);
            $this->default_controller = substr($this->default_controller, strrpos($this->default_controller, \'/\')+1, strlen($this->default_controller));
            
        }

#4
[eluser]the real rlee[/eluser]
Hmmm im still testing but this is the last bit of code ive used and seems to be ok now (cut and paste same place as above):

Code:
// RL default_controller in subdir patch
            if (strrpos($this->default_controller, \'/\')) {
                $this->set_directory(substr( $this->default_controller, 0, strrpos($this->default_controller, \'/\')));
                $this->default_controller = substr($this->default_controller, strrpos($this->default_controller, \'/\')+1, strlen($this->default_controller));
            }

#5
[eluser]Unknown[/eluser]
it seems like ur solving ur own problem..
keep up the good work!!
i cant answer ur question coz im new here..
hee hee..
God Bless!

#6
[eluser]the real rlee[/eluser]
Haha yeah \"thinking out loud\" i call it Tongue. Welcome horns Smile

#7
[eluser]marcoss[/eluser]
Let me see if i got your point, you want to do this?

Code:
$route[\'default_controller\']    = \'dir/controller\';

or this,

Code:
$route[\'default_controller\']    = \'dir/controller/some_method\';

#8
[eluser]the real rlee[/eluser]
Hi marcoss,

my default_controller is within a subdir like this;

Code:
$route[\'default_controller\']    = \'dir/controller\';

and unfortunately setting the config value doesnt work as it should

#9
[eluser]marcoss[/eluser]
You are right, it doesn\'t work as expected :S

You can try this workaround to avoid messing with the code,

Code:
//routes config
$route[\'default_controller\'] = \"dummy\";

//dummy controller
class Dummy extends Controller {

    function Dummy(){
        parent::Controller();
        $this->load->helper(\'url\');
    }
    
    function index(){
        redirect(\'dir/controller\',\'refresh\');
    }
    
}

#10
[eluser]sexy22[/eluser]
haha .....Thanks。。I have solved the problem .marcoss reply extremely good.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.