CodeIgniter looks for Frontend
controller with home
method. You can solve it on two ways. First iw to make Home.php
controller in controllers
directory with next code:
<?php defined('BASEPATH') OR exit('Restricted area!');
class Frontend extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->home();
}
public function home()
{
redirect('frontend/home', 'refresh');
}
}
with APPPATH.'config/routes.php'
code
$route['default_controller'] = 'home';
Second way is to use custom made router class:
<?php
/*
* Custom router function v 0.1
*
* Add functionality : read into more than one sub-folder
*
*/
class MY_Router extends CI_Router
{
public function __construct()
{
parent::__construct();
}
public 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]);
}
}
Credits.