Detectando el dispositivo en Symfony con MobileDetectBundle

Instalación del Bundle

composer require suncat/mobile-detect-bundle
<?phppublic function registerBundles(){$bundles = [     // ...
new SunCat\MobileDetectBundle\MobileDetectBundle(),
];}

Ejemplo de uso

$mobileDetector = $this->get(‘mobile_detect.mobile_detector’);if($mobileDetector->isTablet()){// soy una tablet}else if($mobileDetector->isMobile()){// soy un movil}
$mobileDetector->isAndroidOS();$mobileDetector->isBlackBerryOS();$mobileDetector->isPalmOS();$mobileDetector->isSymbianOS();$mobileDetector->isWindowsMobileOS();$mobileDetector->isiOS();$mobileDetector->isbadaOS();
$mobileDetector->isChrome();$mobileDetector->isSafari();$mobileDetector->isDolfin();$mobileDetector->isOpera();$mobileDetector->isSkyfire();$mobileDetector->isIE();$mobileDetector->isFirefox();
{% if is_mobile() %}<h1>Movil</h1>{% endif %}{% if is_ios() %}<h1>Dispositivo iOS</h1>{% endif %}
mobile_detect:
redirect:
mobile:
is_enabled: true
host: http://m.midominio.es
status_code: 301
action: redirect
tablet: ~
switch_device_view: ~

Caso de Uso

--

--

Full Stack Web Developer — adrianalonso.es

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store