0

Im trying to buil a mobile version of my website, usign Cakephp and JQueyrMobile. For the Cakephp part i opted to use the following in app_controller:

    if($this->RequestHandler->isMobile() || isset($this->params['url']['mobile'])) {
       $this->layout = 'mobile';
       $this->isMobile = true;
    }
    $this->set('is_mobile', $this->isMobile);

    if($this->isMobile) {
           $this->action = 'mobile/'.$this->action;
     }

Thank i create the /mobile/ folder for every controller/view and it works fine. I just have a problem with the home.ctp ! i created the alternative mobile version in /views/pages/mobile/home.ctp but it loads the /views/pages/home.ctp.

What should i do in order to redirect to the mobile version of home.ctp usign the code above ? Thanks!

pedrosss
  • 57
  • 4
  • 11

1 Answers1

3

Have you tried using beforeFilter and afterFilter in your AppController?

I use this for the mobile version of one of my Cake applications:

  function beforeFilter() {
    if ($this->RequestHandler->isMobile()) {
      $this->is_mobile = true;
      $this->set('is_mobile', true );
      $this->autoRender = false;
    }
  }

And afterFilter:

  function afterFilter() {
    if (isset($this->is_mobile) && $this->is_mobile) {
      $view_file = file_exists( VIEWS . $this->name . DS . 'mobile/' . $this->action . '.ctp' );
      $layout_file = file_exists( LAYOUTS . 'mobile/' . $this->layout . '.ctp' );
      $this->render($this->action, ($layout_file?'mobile/':'').$this->layout, ($view_file?'mobile/':'').$this->action);
    }
  }

This code comes from another question on mobile content in Cake, have a look at this answer for more information. Another answer on that same question deals with layouts.

Community
  • 1
  • 1
mensch
  • 4,411
  • 3
  • 28
  • 49