settermjd / zf2forbeginners

The aim of this repository is to support the upcoming book - Zend Framework 2 For Beginners https://leanpub.com/zendframework2-for-beginners
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

FeedsController / manageAction / $this->feedTable needs declaration and construct #7

Closed johnchadwick closed 9 years ago

johnchadwick commented 9 years ago

Page 92: At this point you must add declarations and construct to support: $this->_feedTable (you later changed code to $this->feedTable) This code: use BabyMonitor\Tables\FeedTable; /* * @var FeedTable / protected $feedTable;

public function __construct(FeedTable $feedTable) { $this->_feedTable = $feedTable; }

johnchadwick commented 9 years ago

I'm wrong, don't need this yet.

johnchadwick commented 9 years ago

It looks like the construct code is tied to the FeedsControllerFactory. I get error: Argument 1 passed to BabyMonitor\Controller\FeedsController::__construct() must be an instance of BabyMonitor\Tables\FeedTable To make this work, where you click to edit, I had to go the way of the zend online tutorial, which is: if ($feed = $this->getFeedTable()->fetchById($feedId)) { $form->setData($feed->getArrayCopy()); Below add the function: public function getFeedTable(){ if(!$this->feedTable){ $sm = $this->getServiceLocator(); $this->feedTable = $sm->get('BabyMonitor\Tables\FeedTable'); } return $this->feedTable; }

johnchadwick commented 9 years ago

Also same idea for the save: $feed->feedId = $this->getFeedTable()->save($feed);

settermjd commented 9 years ago

I've updated all references to _feedTable to feedTable in the chapter on controllers and actions and that'll be available in the next release of the book.