CodeIgniter Forums
Codeigniter 3 controller in sub folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Codeigniter 3 controller in sub folder (/showthread.php?tid=68126)



Codeigniter 3 controller in sub folder - rahulemaity - 05-29-2017

In controller I have a folder named "landing".Inside this folder I have a controller name "Landingg.php"
code
------
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Landingg extends CI_Controller {
    public function __construct() {
parent::__construct();
$this->load->helper('url');
    }

    public function index() {
echo 12;
    }

}

when I hit the url "http://localhost/ci/landing/landingg/" it shows object not found.Plz help how to implements and call controller with in sub folder in codeigniter 3


RE: Codeigniter 3 controller in sub folder - Sky - 05-29-2017

(05-29-2017, 10:09 AM)[email protected] Wrote: In controller I have a folder named "landing".Inside this folder I have a controller name "Landingg.php"
code
------
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Landingg extends CI_Controller {
    public function __construct() {
parent::__construct();
$this->load->helper('url');
    }

    public function index() {
echo 12;
    }

}

when I hit the url "http://localhost/ci/landing/landingg/" it shows object not found.Plz help how to implements and call controller with in sub folder in codeigniter 3

Create file MY_Router.php in application/core directory with code:
PHP Code:
<?php
class MY_Router extends CI_Router {

protected function 
_validate_request($segments)
 {
 
$c count($segments);
 
$directory_override = isset($this->directory);

 
// Loop through our segments and return as soon as a controller
 // is found or when such a directory doesn't exist
 
while ($c-- > 0)
 {
 
$test $this->directory
 
.ucfirst($this->translate_uri_dashes === TRUE str_replace('-''_'$segments[0]) : $segments[0]);

 if ( ! 
file_exists(APPPATH.'controllers/'.$test.'.php')
 && 
$directory_override === FALSE
 
&& is_dir(APPPATH.'controllers/'.$this->directory.$segments[0])
 )
 {
 
$this->set_directory(array_shift($segments), TRUE);
 
               while(count($segments) > && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]))
 
               {
 
                   $this->set_directory($this->directory $segments[0]);
 
                   $segments array_slice($segments1);
 
               }
 continue;
 }

 return 
$segments;
 }

 
// This means that all segments were actually directories
 
return $segments;
 }




RE: Codeigniter 3 controller in sub folder - Sky - 05-29-2017

Sorry, I think my code is wrong for your situation.
First of all check your route config. E.g.
$route['landing/landingg'] = 'landing/landingg/index';
And your folder must be upper case. Landing.


RE: Codeigniter 3 controller in sub folder - InsiteFX - 05-29-2017

Did you set your base_url in ./application/config/config.php ?