I want to use the same Models and Controllers which I have for our website,and then create two separate 'Views' folders in the application directory,one for web version and one for mobile version.And then load the desktop view if the website is being accessed from a desktop and mobile views in the other case.Kindly guide me if it can be done and how.
EDIT: this is the function which assigns the View folder path in Codeigniter/system/loader.php:
function __construct() {
$this->_ci_view_path = APPPATH.'views/';
$this->_ci_ob_level = ob_get_level();
$this->_ci_library_paths = array(APPPATH, BASEPATH);
$this->_ci_helper_paths = array(APPPATH, BASEPATH);
$this->_ci_model_paths = array(APPPATH);
log_message('debug', "Loader Class Initialized");
}
so if I apply this check here:
if($this->agent->mobile()){
$this->_ci_view_path = APPPATH.'views/mobile_view';
}
Is this the way to go? –
This link might help you to identify the type of device on which your web application is being accessed. Create a library for the same and include it in constructor of your controller's class.
Now you can change the view in a following way:
if ($detect->isMobile()) {
$view_folder = 'views/mobile/';
}
else{
$view_folder = 'views/normal/';
}
$this->load->view($view_folder.index, $data); //$data is the same variable that you are going to use into your views.