2

I work on Symfony 2.3 and I installed MobileDetectBundle that works on this symfony version:

I configured the bundle accordingly

AppKernel.php

new SunCat\MobileDetectBundle\MobileDetectBundle(),

config_mobile.yml

mobile_detect:
    redirect:
        full:
            is_enabled: true            # default false
            host: http://page.com       # with scheme (http|https), default null, url validate
            status_code: 301            # default 302
            action: redirect            # redirect, no_redirect, redirect_without_path
        mobile:
            is_enabled: true
            host: http://m.page.com
            status_code: 301
            action: redirect
        tablet:
            is_enabled: true
            host: http://t.page.com
            status_code: 301
            action: redirect
    switch_device_view:
        save_referer_path: true
    service:
        mobile_detector: mobile_detect.mobile_detector.default
    device_view_class: SunCat\MobileDetectBundle\Helper\DeviceView
    request_listener_class: SunCat\MobileDetectBundle\EventListener\RequestListener
    extension_class: SunCat\MobileDetectBundle\Twig\Extension\MobileDetectExtension

in my service.yml

services:
    mobile_detector: @mobile_detect.mobile_detector.default

in app_mobile.php

$kernel = new AppKernel('mobile', false);

The bundle works with the mobiledetect classes. Both of them are present in my vendor, so I guess that the installation was done properly

I restarted my server, PHP, cleared the cache but still it doesn't show me my redirection in the URL.

Is it possible in some cases that Symfony doesn't recognize a bundle? Does that happens depending on the version you are?

chicken burger
  • 774
  • 2
  • 12
  • 32
  • How do you see that redirection doesn't work? – merezha Oct 19 '17 at 09:35
  • in the url, when I go on the mobile version with firebug, it actually doesn't redirect me. – chicken burger Oct 19 '17 at 09:38
  • Do you see changes in Symfony Toolbar ("Device detection")? Have you tried to use "device_view" parameter for testing? – merezha Oct 19 '17 at 09:41
  • Yes I tried all that but seems that my listener in config.yml are not took into account. So maybe I thought something was wrong in my code. – chicken burger Oct 19 '17 at 09:55
  • Do you override some listeners? It's not clear from your description. And why you add default mobile_detector to services.yml? It's not required by default – merezha Oct 19 '17 at 10:05
  • I took off the line in service.yml. I tried to follow the doc more and I created a `config_mobile.yml` file and `app_mobile.php` like the doc said. It seems to work a bit more but tells me this error now `The child node "switch_device_view" at path "mobile_detect" must be configured.` (i will update my question) – chicken burger Oct 19 '17 at 10:18
  • You should add **switch_device_view** under **mobile_detect** in your configs – merezha Oct 19 '17 at 10:25
  • yeah, that doesn't do the trick either. I'm not sure this bundel version works on my symfony version. Maybe that is the problem – chicken burger Oct 19 '17 at 10:51

1 Answers1

-2

Try this :

mobile_detect:
redirect:
    mobile: ~
    tablet: ~
switch_device_view: ~
mohamed jebri
  • 261
  • 3
  • 13