I'm very new to zend framework 2 and I've been reading the docs and absorbing it as best I can.
I'm working through the zend skeleton tutorial and its all working but there's a minor point I don't understand.
In the album controller you're instructed to make a call to the table gateway to select all records - specifically $this->getAlbumTable()->fetchAll(). But the method that gets called isn't one I've created so can someone explain how getAlbumTable resolves to what it does. I would have expected to have called the serviceManager in the same way you call an invokable or factory - i.e. $sm->get('AlbumTableGateway')
Appreciate any advice you can give to a ZF2 newbie.
class AlbumController extends AbstractActionController
{
protected $albumTable;
public function indexAction()
{
return new ViewModel(array(
'albums' => $this->getAlbumTable()->fetchAll(),
));
}
Did you skip a step?
$this->getAlbumTable()
(missing from the controller in your code) should return an instance ofAlbumTable
. This class (which you should have already created) has afetchAll()
method.Take a look at the "Model files" section of the tutorial you linked to in your question: http://framework.zend.com/manual/current/en/user-guide/database-and-models.html#the-model-files