Welcome Guest, Not a member yet? Register   Sign In
Mobile and Normal View Files
#1

[eluser]EzraBynx[/eluser]
I am very new to CodeIgniter and I would like to know if this follows best practices of the framework.

This code takes an incoming request and detects what kind of browser is requesting it. From there it defines the browser. This information is then used in the loader class to automatically add the folder name to the view file.

Thank you for your feedback.

My_Loader.php located in ./application/core/MY_Loader.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_Loader extends CI_Loader {
  
public function __construct()
{
  parent::__construct();
}

public function view($view, $vars = array(), $return = FALSE)
{
  $view = BROWSER_TYPE . $view;
  parent::view($view, $vars, $return);
}
}

/* End of file MY_Loader.php */
/* Location: ./application/core/MY_Loader.php */

MY_Controller located in ./application/core/MY_Controller.php */

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_Controller extends CI_Controller {
  
public function __construct()
{
  parent::__construct();
  
  $this->load->library('user_agent');
  
  if ($this->agent->is_mobile())
  {
   DEFINE('BROWSER_TYPE', 'mobile/');
  }
  else
  {
   DEFINE('BROWSER_TYPE', '');
  }
}
}

/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */




Theme © iAndrew 2016 - Forum software by © MyBB