Welcome Guest, Not a member yet? Register   Sign In
SIMPLE Backend / Frontend : configuration. A.K.A "poor man's modules"
#1

[eluser]rawoke083[/eluser]
Hi Guys
I thought i present this solution might not be the best but works great for me.

We all know CodeIgniter don't have modules "out of the box" not that it's a bad thing but I usually need it. ATLEAST a admin/backed module:

Case Study:

1) So we have http://www.mysite.com: Frontend site build on CI.
2) We have a http://admin.mysite.com Backend site build on CI (same codebase / instal as frontend)

3) Directory struct:

>application\
-->controllers\
---->product.php (frontend controller)
-->views\
----->product\
------->list.php (frontend list view of product)
-->modules\ (NB ! NB !)
---->admin\
------>controllers\
-------->product.php (admin controller)
---->views\
------->product\
--------->list.php (admin list view of product)

4) Code changes in index.php
Quote: // round about line 120 towards the end
// NOTiCE WE CHECK FOR 'ADMIN.'

$controller_path_prefix=$application_folder."/";
$is_admin_site = false;
if(strstr($_SERVER['HTTP_HOST'],'admin.'))
{
$controller_path_prefix=$application_folder.'/modules/admin/';
$is_admin_site = true;
}

//define it's ass Smile
define('CONTROLLER_PATH_PREFIX',$controller_path_prefix);


/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/

/////////// other defines follows.........

//VIEW PATH NB NB NB NB !!
if($is_admin_site)
{
define('VIEW_PATH', $application_folder.'/modules/admin/views/');
}
else
{

define('VIEW_PATH', $application_folder.'/views/');
}


--------------------------
Code changes CodeIgniter.php +- LINE 222


Quote://add CONTROLLER_PATH_PREFIX
if ( ! file_exists(CONTROLLER_PATH_PREFIX.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
{
show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}

include(CONTROLLER_PATH_PREFIX.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);


---------------------------
Code Changes in Loader.php in constructor
Quote:function __construct()
{


...
//use VIEW_PATH
$this->_ci_view_path = VIEW_PATH;
....

}


-----------------------------------


So ja 3 files to edit may be 10 lines and you can have frontend/backend support

I'm sure there are ways to improve on this.

Comments welcome




Theme © iAndrew 2016 - Forum software by © MyBB