我试图显示带有zend db的列表,但返回错误:
<div class="flex">
<ol>
<li><span>1</span></li>
<li><span>2</span></li>
<li><span>3</span></li>
<li><span>4</span></li>
<li><span>5</span></li>
<li><span>6</span></li>
<li><span>7</span></li>
<li><span>8</span></li>
<li><span>9</span></li>
</ol>
<ol class="lower">
<li><span>a</span></li>
<li><span>b</span></li>
<li><span>c</span></li>
<li><span>d</span></li>
<li><span>e</span></li>
<li><span>f</span></li>
<li><span>g</span></li>
<li><span>h</span></li>
<li><span>i</span></li>
<li><span>j</span></li>
<li><span>k</span></li>
<li><span>l</span></li>
<li><span>m</span></li>
<li><span>n</span></li>
<li><span>o</span></li>
<li><span>p</span></li>
<li><span>q</span></li>
<li><span>r</span></li>
<li><span>s</span></li>
<li><span>t</span></li>
<li><span>u</span></li>
<li><span>v</span></li>
<li><span>w</span></li>
<li><span>x</span></li>
<li><span>y</span></li>
<li><span>z</span></li>
</ol>
<ol class="upper">
<li><span>a</span></li>
<li><span>b</span></li>
<li><span>c</span></li>
<li><span>d</span></li>
<li><span>e</span></li>
<li><span>f</span></li>
<li><span>g</span></li>
<li><span>h</span></li>
<li><span>i</span></li>
<li><span>j</span></li>
<li><span>k</span></li>
<li><span>l</span></li>
<li><span>m</span></li>
<li><span>n</span></li>
<li><span>o</span></li>
<li><span>p</span></li>
<li><span>q</span></li>
<li><span>r</span></li>
<li><span>s</span></li>
<li><span>t</span></li>
<li><span>u</span></li>
<li><span>v</span></li>
<li><span>w</span></li>
<li><span>x</span></li>
<li><span>y</span></li>
<li><span>z</span></li>
</ol>
</div>
文件:
BLOGCONTROLLER.PHP
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
MODULE.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.CONFIG.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));
},
],
];
}
}
POST.PHP
namespace Blog;
return [
'router' => [],
'view_manager' => [
'template_path_stack' => [
'blog' => __DIR__ . "/../view"
]
]
];
POSTTABLE.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
];
}
}