1
Argument 1 passed to Album\Controller\AlbumController::__construct() must be an instance of Album\Controller\AlbumTable, instance of Album\Model\AlbumTable given,, called in /var/www/html/zf/module/Album/src/Module.php on line 43
My Module.php is;
<?php
namespace Album;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Db\TableGateway\TableGateway;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
// Add this method:
public function getServiceConfig()
{
return [
'factories' => [
Model\AlbumTable::class => function($container) {
$tableGateway = $container->get(Model\AlbumTableGateway::class);
return new Model\AlbumTable($tableGateway);
},
Model\AlbumTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\AlbumController::class => function($container) {
return new Controller\AlbumController(
$container->get(Model\AlbumTable::class)
);
},
],
];
}
}
我的AlbumController就像;
<?php
namespace Album\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Album\Model;
class AlbumController extends AbstractActionController
{
// Add this property:
private $table;
// Add this constructor:
public function __construct(AlbumTable $table)
{
$this->table = $table;
}
public function indexAction()
{
return new ViewModel([
'albums' => $this->table->fetchAll(),
]);
}
public function addAction()
{
}
public function editAction()
{
}
public function deleteAction()
{
}
}
能否请你告诉我什么,我做错了什么?我在Zend Framework中很新。这是我试图运行的教程应用程序。我遵循所有步骤,但有很多问题,我一一解决了所有这些问题,现在我被困在这里。
那么,那个错误信息怎么样都难以理解? – RiggsFolly
我已经提到了这个错误。很容易理解错误是什么。但无法理解解决方案。 –
结论:'必须是Album \ Controller \ AlbumTable的一个实例,Album \ Model \ AlbumTable的实例' – hassan