• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Caching Driver] Problem with function get()

Hi everyone!

I have a problem with Caching Driver in CI 2.1.2.

When I try to run this code in my view file:
$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));

if ( ! $foo = $this->cache->get('foo'))
     echo 'Saving to the cache!<br />';
     $foo = 'foobarbaz!';

     // Save into the cache for 5 minutes
     $this->cache->save('foo', $foo, 300);

echo $foo;

I get thouse error messages:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$cache

Filename: views/index.php

Line Number: 21

Fatal error: Call to a member function get() on a non-object in /home/komeniusz/public_html/sejny/application/views/index.php on line 21

What's wrong?

The cache driver is not available to the $this scope inside the view.

Besides, loading views (and subsequently, loading cached views) should be done in the controller, not the view file. Move your code to the controller and it should be fine.

Thank you for your help Smile

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.