Open johnchadwick opened 9 years ago
@johnchadwick thanks for reporting this. I'll get the code corrected.
I've found the source of the error. Just have to fix it up, update some tests and commit the change.
I committed a set of patches on develop which address the issue. But I plan to continue to investigate further to see if other problems exist. Thanks for letting me know. I'll be making an update to the book to correct the issues there too.
Thanks for responding so quickly. I see it at: https://github.com/settermjd/zf2forbeginners Branch: Develop (as opposed to Master). I will download and check it out. So far only a few minor issues I'll add today. I got to page 86 and saw my one record so I was happy that worked out. If one day you get the time you could always have a set of code on github for each milestone or chapter. Thanks again.
No worries @johnchadwick I've just made another set of commits, this time showing tests as well. Hope they further help you out.
Downloaded Branch: Develop and got this for the main page. I am looking through your commits and trying to resolve but I am sure you'll have it figured out quickly. Thanks. Catchable fatal error: Argument 1 passed to Zend\Paginator\Adapter\Iterator::__construct() must implement interface Iterator, string given, called in C:\zf2forbeginners\module\BabyMonitor\src\BabyMonitor\Controller\FeedsController.php on line 191 and defined in C:\zf2forbeginners\vendor\zendframework\zendframework\library\Zend\Paginator\Adapter\Iterator.php on line 36
Hi @johnchadwick I did come across it, but only intermittently. I'll have a look and see about making the code more defensive.
I believe you just had a little error in your logic. Please review the following and let me know if it makes sense. In addition, as I previously stated, $this->_cache will never be null or empty as one can see using: var_dump($this->_cache). Perhaps one could throw an error if $this->cache is empty?
I believe I figured out why you thought the issue was intermittent. Before you changed your code, the data was cached in the file: \data\cache\zfcache-d8\zfcache-recent_feeds.dat. If you empty (but not delete) this file of the cached contents, you will again see the error.
public function indexAction() { // if (!is_null($this->cache)) { if (!$this->cache->hasItem(self::KEY_ALL_RESULTS)) { $resultset = $this->cache->getItem(self::KEY_ALL_RESULTS); } else { $resultset = $this->feedTable->fetchMostRecentFeeds(self::DEFAULT_FEED_COUNT); $this->cache->setItem(self::KEY_ALL_RESULTS, $resultset->toArray()); } // } else { // $resultset = $this->feedTable->fetchMostRecentFeeds( // self::DEFAULT_FEED_COUNT // ); // }
Using "Development" branch code on github... The above problem still exists.
My code above will cause an error in ControllerTest.php, testFeedManagePageCanBeAccessed. This works: if ($this->cache && $this->cache->hasItem(self::KEY_ALL_RESULTS)) { $resultset = $this->cache->getItem(self::KEY_ALL_RESULTS); } if(empty($resultset)) { $resultset = $this->feedTable->fetchMostRecentFeeds(self::DEFAULT_FEED_COUNT); if($this->cache) { $this->cache->setItem(self::KEY_ALL_RESULTS, $resultset->toArray()); } }
@johnchadwick thanks; I'll check it out
Using the code downloaded and just adding local.php and a modication to global.php for the database connection:
Regarding loading the index page for the first time: public function indexAction if (!is_null($this->_cache)) { //this always evaluates to true !$this->_cache->hasItem(self::KEY_ALL_RESULTS) //this always evaluates to false //Therefore fetchMostRecentFeeds never gets run so no records are displayed.
// (!is_null($this->_cache)) { // replaced with: if (!isset($this->_cache)) { // Then it runs and this shows I have a record: exit(var_dump($resultset));
// However index.phtml calls: 'babymonitor/feeds/results/search/default' => DIR . '/../view/baby-monitor/feeds/feed-results.phtml' // feed-results.phtml calls $this->paginator // However in FeedsController indexAction there is no reference to paginator, but searchAction does.
//I'm stuck, thanks.