// One More

function blog() {

/**
* @author     Mikey
* @date       2011-08-30 01:58:15
* @shorturl   http://kwn.me/1olk
**/

$this->Post->read('CakePHP - Creating a Mobile Friendly Site');

With the advent of iOS and Android and the mobile boom, people now more than ever need to be able to access your content quick and easily on the move.

As both Android and iOS devices have a good web browser which is (usually) webkit, this is now more easy than you would think.

As most mobile devices have webkit powered browsers, you can usually bet that CSS3 and HTML5 are strongly supported, so you can create a mini web-app using those, and with CakePHP's in-built RequestHandler, the once tricky task detecting all of those mobile devices is now easier than ever.

First, you'll need to check if the visitor is a web browser, or a mobile browser through use of the RequestHandler (as mentioned earlier) and the isMobile action.

Stick the following into your beforeFilter() action of your AppController.

        if ($this->RequestHandler->isMobile()) {
            // do this when mobile device detected
            $this->layout = 'mobile';
            $mView = strtolower( DS .'mobile' . DS . $this->params['controller'] . DS . $this->params['action']);
            if (file_exists(VIEWS . ' . $mview .')) {
                $this->viewPath = $mView;
            }
        }


Now, there are possibly many ways of doing this, such as themes, elements, but I've opted to create a new layout, called /app/views/layouts/mobile.ctp - this will be the same as your /layouts/default.ctp for your web site.

Now visit your site on a mobile device, you'll see that it's a different layout to your normal site!

All you have to do now is to put your views inside /app/views/mobile - so for a posts view, it would be /app/views/mobile/posts/index.ctp for example.

Visit One More Function on a mobile device, see what I've done (or look at this picture :p) http://dl.dropbox.com/u/1296700/iPod/Photo%2030-08-2011%2020%2009%2002.png

$this->Post->read('Comments');

Ping said

Tuesday August, 30 2011 14:08:18

Pong

}