Welcome Guest, Not a member yet? Register   Sign In
output cache problem with mobile/desktop view.
#1

[eluser]Unknown[/eluser]
Hi guys.

I have a site with different views, one for desktop and one for mobile devices.

but when I try to load a view to mobiles using the method is_mobile () does not work.

I think it's because it never enters to main controller for checking the user agent.

Code:
public function index(){
  $this->load->model('my_model');

  $data['xxxx'] = xxxxx;

  if($this->agent->is_mobile()){
    $this->parser->('my_view', $data);
  }else{
    $this->parser->('my_view_mobile', $data);
  }
  $this->output->cache($time);
}

how can i use the output->cache with agent class ???

i hope you guys understand me.

thx
#2

[eluser]rana[/eluser]
so, as you have to check the agent for each request, you must not cache the output directly. Yes, after you call "$this->output->cache($time)" , it will server the same data instead of entering the controller code execution. So, this is what I will recommend : get the view data returned to a variable. cache it as object cache, and serve from cache. Here is a pseudocode what I would do:

Code:
$template = "";
if($this->agent->is_mobile()){
    $tempate = "my_view";
  }else{
     $tempate = "my_view_mobile";
  }

if ( ! $cache_data = $this->cache->get($template))
{
     $view_result =   $this->parser->('my_view_mobile', $data, true);
     $this->cache->save($template, $view_result, $time);
     $cache_data = $view_result;
}
print($cache_data);
#3

[eluser]Unknown[/eluser]
is a good solution, but i can't use any driver for cache.

is a require from my client.

another solution ?
#4

[eluser]rana[/eluser]
It isn't necessary to use a driver. You can use file system as well. load cache driver as below:

Code:
$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));

The above code will look for 'apc' driver first, if not available, will work with 'file' system. If you are strict about no driver, use 'file' only. You can read more about my codeigniter caching tutorial. Thanks.





Theme © iAndrew 2016 - Forum software by © MyBB