CodeIgniter and HMVC questions CodeIgniter and HMVC questions codeigniter codeigniter

CodeIgniter and HMVC questions


Just open or create core/MY_Controller.php, create a MY_Controller class and have it extend MX_Controller, then in the same file create your other base controllers and have them extend MY_Controller. Here's an example you can copy/paste to get you started:

<?php defined('BASEPATH') OR exit('No direct script access.');class MY_Controller extends MX_Controller {    public function __construct()    {        // do some stuff here that affects all controllers    }}class Frontend_Controller extends MY_Controller {    public function __construct()    {        parent::__construct();    }}class Backend_Controller extends MY_Controller {    public function __construct()    {        parent::__construct();        // Check admin login, etc.    }}/* end file application/core/MY_Controller.php */

As far as "multiple themes" go, not sure what you need. Stylesheets? HTML Templates? Do you need to have the users switch them or will you do it manually? Do you need to detect mobile devices and change the theme accordingly? All of the above? The "best" way is going to depend on your implementation.

I am thinking of creating 2 libraries extends from MY_Controller.php and auto load them. Will that work?

Not sure why you'd need or want to... just don't do it. You should only extend these classes with other controllers.

About the themes, I want to have multiple themes for views like: - /views/theme1/view_files.php - /views/theme2/view_files.php About js/css/images, I can arrange myself. At the beginning I will fix the theme but later, I may allow user to choose. With MVC, I can put themes in subfolders of /views/ as above but with HMVC, I have to find another way to arrange them in to themes because view folders are separated (I want all view files of same theme will be in only 1 folder)..

Since this is too broad a question to tackle here, and you don't seem to have even tried anything yet, I'll will give you a bare minimum example:

class MY_Controller extends MX_Controller {    public function __construct()    {        // do some stuff here that affects all controllers        $this->theme = 'theme1'; // matches your directory name in /views/themes/    }}

From your controller:

$this->load->view('themes/'.$this->theme.'/my_view_file');

Using HMVC, the file will always be looked for in the current module, then fall back to the default application directories if it doesn't exist. If for some reason you need to be explicit, you can say prepend the path with the module name (like for cross-loading resources between modules). Example:

// From "blog" module$this->load->view('events/index');// We just loaded `modules/events/views/index` from the blog module

Anyways, this is not a full solution, but hopefully it gets you started with an idea. There are millions of ways to do this, here are two template libraries that already support themes: