I’ve followed the Album example that was created for the new ZF2 tutorial. For first module, it all worked great and I was able to modify to show the data that I want to use for my application.
My problem is adding a second module, and, more complex, it managing 2+ tables of data. Each time I go to the page, I get the Apache error page, which isn’t very helpful. The only main Class I modified was the Module.php int he second module’s directory. Maybe someone can see how wrong my guess was.
Background on the module: The view will show 4 types of tables that include Fosters and Volunteers. I created a Model and Table for each. All seems to be pretty good, except I did modify the factories setting to include each Table (FosterTable and VolTable). Do you think this is were my error could be?
I was working form this page: http://framework.zend.com/manual/2.0/en/user-guide/database-and-models.html
For the /TeamMgr/Module.php, I added the following:
namespace TeamMgr;
use TeamMgr\Model\FosterTable;
use TeamMgr\Model\VolTable;
class Module
{
public function getServiceConfig()
{
return array(
'factories' => array(
'TeamMgr\Model\VolTable' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new VolTable($dbAdapter);
return $table;
},
'TeamMgr\Model\FosterTable' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new FosterTable($dbAdapter);
return $table;
},
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
Then in my controller I added:
public function indexAction(){
return new ViewModel(array(
'fosters'=>$this->getFosterTable()->fetchAll(),
));
return new ViewModel(array(
'vols'=>$this->getVolTable()->fetchAll(),
));
}
So how completely off am I?
You can’t call
returnmore than once. What is happening is that the execution of the function is terminated with the firstreturncall and the second one is never called. You need to write:It’s basic PHP. So I’d suggest to learn PHP first, before learning ZF. ZF is very complex even for someone seasoned in plain vanilla PHP. There are better frameworks for beginners (like code igniter, kohana or cakephp) – you should start there IMO…