I'm running threw a simple Zend framework tutorial trying to familiarize
myself with the framework. I have a simple application that stores and
displays cd albums and artist names. My problem lies in my index action
where I generate the full list. On the first load of the this action I do a
fectchAll from my Zend DB Table object and save the result with Zend Cache
and then send the result to the view which loops through the result and
displays it. The first load works fine. On subsequent loads I try to load
the date from Zend Cache and send it on to the view. However this time the
view throws an error/notice:
Notice: Trying to get property of non-object in...
When I do a Zend Debug Dump of the result of the Zend Cache load it
*appears* that what was returned was the proper object:
object(__PHP_Incomplete_Class)#21 (8) {
["__PHP_Incomplete_Class_Name"] => string(20) "Zend_Db_Table_Rowset"
["_data:protected"] => array(4) {
[0] => array(3) {
["id"] => string(3) "330"
["artist"] => string(15) "Michael Jackson"
["title"] => string(8) "Thriller"
}
[1] => array(3) {
["id"] => string(3) "331"
["artist"] => string(5) "AC/DC"
["title"] => string(13) "Back in Black"
}
[2] => array(3) {
["id"] => string(3) "332"
["artist"] => string(15) "Backstreet Boys"
["title"] => string(10) "Millennium"
}
[3] => array(3) {
["id"] => string(3) "334"
["artist"] => string(4) "asdf"
["title"] => string(4) "asdf"
}
}
["_tableClass:protected"] => string(5) "Album"
["_rowClass:protected"] => string(17) "Zend_Db_Table_Row"
["_pointer:protected"] => int(0)
["_count:protected"] => int(4)
["_rows:protected"] => array(0) {
}
["_stored:protected"] => bool(true)
}
>From what I can tell I think I have everything setup properly based on what
i was able to scrounge up online. Any insight or advice would be greatly
appreciated.
### System & app Details
PHP Version 5.2.0-8+etch7 (Debian)
Apache2
### Front Controller
<?php
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('America/Los_Angeles');
set_include_path('.' . PATH_SEPARATOR . '../library'
. PATH_SEPARATOR . '../application/models/'
. PATH_SEPARATOR . get_include_path());
include "Zend/Loader.php";
Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Debug');
Zend_Loader::loadClass('Zend_Cache');
//Load Application Configuration
$config = new Zend_Config_Ini('../application/config.ini','general');
$registry = Zend_Registry::getInstance();
$registry->set('config',$config);
//Setup Database
$db = Zend_Db::factory($config->db->adapter,$config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
//Setup Cache
$frontendOptions = array(
'lifetime' => 7200, // cache lifetime of 2 hours
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => '../cache/' // Directory where to put the cache files
);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions,
$backendOptions);
$registry->set('cache',$cache);
//Setup Controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('../application/controllers');
$frontController->dispatch();
### Index action
function indexAction() {
$this->view->title = "My Albums";
$cache = Zend_Registry::get('cache');
$allAlbums = $cache->load('all_albums');
Zend_Debug::dump($allAlbums);
if ( $allAlbums ) {
Zend_Debug::dump("Pulling from cache");
$this->view->albums = $allAlbums;
} else {
Zend_Debug::dump("Pulling from DB");
$album = new Album();
$this->view->albums = $album->fetchAll();
$cache->save($this->view->albums,'all_albums');
}
}
### View
<?php foreach($this->albums as $album) : ?>
<?php echo $this->escape($album->title);?>
<?php echo $this->escape($album->artist);?>
"<?php echo $this- baseUrl; ?>/index/edit/id/<?php echo
$album->id;?>">Edit
"<?php echo $this- baseUrl; ?>/index/delete/id/<?php echo
$album->id;?>">Delete
<?php endforeach; ?>
--
View this message in context:
http://www.nabble.com/Zend-Cache-dosent-seem-to-be-returning-the-object-I-saved-tf4656895s16154.html#a13306864
Sent from the Zend Framework mailing list archive at Nabble.com.