I played around with this the other night for awhile, this is what I came up with.
Folder Structure:
Controllers
-- -- Admin
-- -- -- -- AdminController.php
-- -- Base
-- -- -- -- BaseController.php
-- -- Frontend
-- -- -- -- FrontController.php
-- -- Home.php
BaseController.php
PHP Code:
<?php namespace App\Controllers\Base;
class BaseController extends \CodeIgniter\Controller
{
public function __construct(...$params)
{
parent::__construct(...$params);
}
} // End of Class BaseController.
AdminController.php
PHP Code:
<?php namespace App\Controllers\Admin;
use App\Controllers\Base\BaseController;
class AdminController extends BaseController
{
public function __construct (...$params)
{
parent::__construct(...$params);
}
} // End of Class AdminController.
FrontController.php
PHP Code:
<?php namespace App\Controllers\Frontend;
use App\Controllers\Base\BaseController;
class FrontController extends BaseController
{
public function __construct(...$params)
{
parent::__construct(...$params);
}
} // End of Class FrontController.
Home.php
PHP Code:
<?php namespace App\Controllers;
// use
//use App\Controllers\Frontend\AdminController;
use App\Controllers\Frontend\FrontController;
// or
// class Home extends AdminController
class Home extends FrontController
{
/**
* Class variables - public, private, protected and static.
* -----------------------------------------------------------------------
*/
/**
* __construct ()
* -----------------------------------------------------------------------
*
* Class Constructor
*
* NOTE: Not needed if not setting values or extending a Class.
*
*/
public function __construct(...$params)
{
parent::__construct(...$params);
}
public function index()
{
echo view('welcome_message');
}
//------------------------------------------------------------------------
} // End of Class Home
/**
* ---------------------------------------------------------------------------
* Filename: Home.php
* Location: ./application/Controllers/Home.php
* ---------------------------------------------------------------------------
*/
Of course I'am not even sure if this is the correct way but it does work for me.
This should get you started on doing sub-folders, I hope it helps.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )