Detect The Mobile Browser To Set Mobile Layout?

Im trying to create another version for mobile phone including Android and Iphone. Just want to ask how to make the theme, layout for the mobile phone with Yii. And how to detect the mobile browser to set the layout for it. Thank in advance :)

Hi @clonevn

You could override init method of components/Controller.php like this

 public function init() {


  if (strpos($_SERVER['HTTP_USER_AGENT'], 'Android'))

            $theme = 'android';

        elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'iPad'))

            $theme = 'ipad';

        elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone'))

           $theme = 'iphone';


           $theme =  'pc';


Then set your theme accordingly :)


Both solution of KonApaz and fburhan89 are awesome. I use them all, thank a lot :lol: