• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter 3 controller in sub folder

#1
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
Reply

#2
(05-29-2017, 11: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;
 }

Reply

#3
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.
Reply

#4
Did you set your base_url in ./application/config/config.php ?
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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