【发布时间】:2017-03-04 08:02:48
【问题描述】:
我是 Zend Framework 3 的新手,我正在做 this 教程:
我有一个 xampp,mysql 设置。
我所做的一切都与本教程中的完全一样。现在我正处于您配置数据库连接的位置。此外,我已经设置了控制器和视图。
在上面的教程链接中,他们使用 php 创建数据库,然后在 config/autoload/global.php .....以下代码:
return [
'db' => [
'driver' => 'Pdo',
'dsn' => sprintf('sqlite:%s/data/zftutorial.db', realpath(getcwd())),
],
];
我已将其编辑为:
'db' => [
'driver' => 'Pdo_Mysql',
'dsn' => 'mysql:dbname=dbname;host=localhost;charset=utf8;username=myuser;password=mypassword',
],
当我调用索引视图的 url 时,出现以下错误:
警告:从第 15 行 C:\xampp\htdocs\zendtest\module\Album\src\Controller\AlbumController.php 中的空值创建默认对象
致命错误:在 null 上调用成员函数 fetchAll() C:\xampp\htdocs\zendtest\module\Album\src\Controller\AlbumController.php 在第 22 行
专辑控制器:
<?php
namespace Album\Controller;
use Album\Model\AlbumTable;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class AlbumController extends AbstractActionController {
private $table;
public function __construct(AlbumTable $table)
{
$this->table = $table;
}
public function indexAction()
{
return new ViewModel([
'albums' => $this->table->fetchAll(),
]);
}
}
我认为连接不起作用??
【问题讨论】:
标签: php mysql zend-framework