Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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. </p> <p>First, I recommend making all controllers inherit from a custom controller. See Phil Sturgeon's post on <a href="http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-base-Classes-Keeping-it-DRY" rel="nofollow noreferrer">Keeping It Dry</a>. 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 <a href="http://codeigniter.com/user_guide/libraries/user_agent.html" rel="nofollow noreferrer">CodeIgniter's native</a> <code>$this-&gt;agent-&gt;is_mobile()</code>:</p> <pre><code>class MY_Controller extends CI_Controller{ function __construct(){ parent::__construct(); $this-&gt;data['agent'] = ($this-&gt;agent-&gt;is_mobile())? 'mobile' : 'desktop'; $this-&gt;load-&gt;vars($this-&gt;data); } } </code></pre> <p>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:</p> <p>Create two directories in your <code>views</code> directory.</p> <pre><code>views desktop mobile </code></pre> <p>And when calling your views:</p> <p><code>$this-&gt;load-&gt;view($this-&gt;data['agent'] . "/theview");</code></p> <p>Regarding the ajax requests you mentioned in a comment -- you can check for those using <a href="http://codeigniter.com/user_guide/libraries/input.html" rel="nofollow noreferrer">CodeIgniter's native</a> <code>$this-&gt;input-&gt;is_ajax_request()</code> 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 <code>is_ajax_request()</code> function to diverge and provide a response that suits the platform.</p> <p>Recommend checking out <a href="https://stackoverflow.com/a/9540985/568884">my answer</a> to another StackOverflow question on view structure for more information.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload