Welcome Guest, Not a member yet? Register   Sign In
[Caching Driver] Problem with function get()
#1

[eluser]Komeniusz[/eluser]
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:
Code:
<?php
$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;
?&gt;

I get thouse error messages:
Code:
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?
#2

[eluser]Aken[/eluser]
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.
#3

[eluser]Komeniusz[/eluser]
Thank you for your help Smile




Theme © iAndrew 2016 - Forum software by © MyBB