Wallogit.com
2017 © Pedro Peláez
Handles detecting mobile browsers
Handles detecting mobile browsers. Results are stored locally for caching calls within the same request, and stored in a cookie for caching across requests., (*1)
Detection regex used from http://detectmobilebrowsers.com/, (*2)
Tested on Yii 1.1.8 - 1.1.14, should work on all versions., (*3)
Install as an application component, in your config:, (*4)
'components' => array(
'detectMobileBrowser' => array(
'class' => 'ext.yii-detectmobilebrowser.XDetectMobileBrowser',
//'secure' => true,
//'httpOnly' => true,
),
),
You can get the current user preference like this:, (*5)
if (Yii::app()->detectMobileBrowser->showMobile) {
// do something
}
By default it will use the automatically detected value. You can also set the preference yourself like this:, (*6)
public function actionShowMobile() {
Yii::app()->detectMobileBrowser->showMobile = true;
$this->redirect(array('/site/index'));
}