Я пытаюсь показать список с Zend DB, но возвращает ошибку:
File:
C:\Users\Ricardo\Desktop\www\zend3\zf-
3\module\Blog\src\Controller\BlogController.php:16
Message:
Too few arguments to function Blog\Controller\BlogController::__construct(),
0 passed in C:\Users\Ricardo\Desktop\www\zend3\zf-
3\vendor\zendframework\zend-servicemanager\src\Factory\InvokableFactory.php
on line 30 and exactly 1 expected
Файлы:
BLOGCONTROLLER.PHP
namespace Blog\Controller;
use Blog\Model\PostTable;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class BlogController extends AbstractActionController
{
private $table;
public function __construct(PostTable $table)
{
$this->table = $table;
}
public function indexAction()
{
$PostTable = $this->table;
return new ViewModel(['posts'=> $PostTable->fetchAll()]);
}
module.php
namespace Blog;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . "/../config/module.config.php";
}
public function getServiceConfig()
{
return [ 'factories' =>
[
Model\PostTable::class => function ($container){
$tableGateway = $container->get(Model\PostTableGateway::class);
return new Model\PostTable($tableGateway);
},
Model\PostTableGateway::class => function($container){
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Post());
return new TableGateway('post', $dbAdapter, null, $resultSetPrototype);
}
]
];
}
public function getControllerConfig()
{
return [ 'factories' =>
[
BlogController::class => function($container){
return new BlogController($container->get(Model\PostTable::class));
},
],
];
}
}
MODULE.CONFIG.PHP
namespace Blog;
return [
'router' => [],
'view_manager' => [
'template_path_stack' => [
'blog' => __DIR__ . "/../view"
]
]
];
Post.php
namespace Blog\Model;
class Post
{
public $id;
public $title;
public $content;
public function exchangeArray(array $data)
{
$this->id = (!empty($data['id'])) ? $data['id']: null;
$this->title = (!empty($data['title'])) ? $data['title']: null;
$this->content = (!empty($data['content'])) ? $data['content']: null;
}
public function getArrayCopy()
{
return [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content
];
}
}
POSTTABLE.PHP
namespace Blog\Model;
use Zend\Db\TableGateway\TableGatewayInterface;
class PostTable
{
private $tableGateway;
public function __construct(TableGatewayInterface $tableGateway){
$this->tableGateway = $tableGateway;
}
public function fetchAll(){
return $this->tableGateway->select();
}
}