I advise against creating multiple controller directories. Controller logic will most likely be the same for a large portion of your site. You can create separate functions in the controller for when the mobile and desktop versions diverge.
First, I recommend making all controllers inherit from a custom controller. See Phil Sturgeon's post on Keeping It Dry. Once this is implemented, you can check whether the request comes from mobile or desktop in this custom 'mother' controller and all descendent controllers will know about it. Use CodeIgniter's native $this->agent->is_mobile()
:
class MY_Controller extends CI_Controller{
function __construct(){
parent::__construct();
$this->data['agent'] = ($this->agent->is_mobile())? 'mobile' : 'desktop';
$this->load->vars($this->data);
}
}
It's your presentation that will change, Not your controllers. Now that you know the origin (agent) of the request, you can render the appropriate content:
Create two directories in your views
directory.
views
desktop
mobile
And when calling your views:
$this->load->view($this->data['agent'] . "/theview");
Regarding the ajax requests you mentioned in a comment -- you can check for those using CodeIgniter's native $this->input->is_ajax_request()
function. When users click links or buttons on your site and a controller is fired, whether on mobile or desktop, they will often share similar functionality (database writes for example)... but you can use the is_ajax_request()
function to diverge and provide a response that suits the platform.
Recommend checking out my answer to another StackOverflow question on view structure for more information.
Hope this helps.