我们尝试实现zf3教程:
https://docs.zendframework.com/tutorials/getting-started/database-and-models/
这很好用,直到我们尝试将新的indexAction()放入RequestTable:
return new ViewModel([
'albums' => $this->table->fetchAll(),
]);`
fetchAll()具有以下定义:
public function fetchAll()
{
return $this->tableGateway->select();
}
通过这样做,网站变白并且不会抛出任何与zendframework相关的错误。只有apache服务器显示:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 66719744 bytes) in Unknown on line 0
我们的module.config.php结构如下:
namespace Request;
use Request\Controller\RequestController;
use Zend\Db\Adapter\AdapterServiceFactory;
use Zend\Router\Http\Segment;
use Zend\Db\Adapter\AdapterInterface;
return [
'dependencies' => [
'factories' => [
AdapterInterface::class => AdapterServiceFactory::class,
],
],
'router' => [
'routes' => [
'request' => [
'type' => Segment::class,
'options' => [
'route' => '/request[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => RequestController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'album' => __DIR__ . '/../view',
],
],
];
如果我们打电话
public function fetchAll()
{
return $this->tableGateway->getTable();
}
相反,然后网站不变为白色,并且在apache中记录没有错误。没有任何事情发生。
我们的global.php应该包含与数据库相关的信息,如下所示:
return [
'db' => [
'driver' => 'pdo_mysql',
'database' => 'test_db',
'username' => 'db_tester',
'password' => 'XXXXXX',
],
];
这是我们的RequestTable.php:
namespace Request\Model;
use RuntimeException;
use Zend\Db\TableGateway\TableGatewayInterface;
class RequestTable
{
private $tableGateway;
/**
* RequestTable constructor.
* @param TableGatewayInterface $tableGateway
*/
public function __construct(TableGatewayInterface $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function fetchAll()
{
return $this->tableGateway->select();
}
这是request.php:
namespace Request\Model;
class Request{
public $request_id;
public $email;
public $type;
public function exchangeArray(array $data)
{
$this->request_id = !empty($data['request_id']) ? $data['request_id'] : null;
$this->email = !empty($data['email']) ? $data['email'] : null;
$this->type = !empty($data['type']) ? $data['type'] : null;
}
}
我们的Module.php如下所示:
namespace Request;
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\RequestTable::class => function($container) {
$tableGateway = $container->get(Model\RequestTableGateway::class);
return new Model\RequestTable($tableGateway);
},
Model\RequestTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Request());
return new TableGateway('request', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\RequestController::class => function($container) {
return new Controller\RequestController(
$container->get(Model\RequestTable::class)
);
},
],
];
}
}
现在我们在添加以下内容后收到以下失败消息:
var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))
错误讯息:
array(10) { [0]=> array(3) { ["file"]=> string(90) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php" ["line"]=> int(505) ["function"]=> string(7) "include" } [1]=> array(5) { ["file"]=> string(74) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/View.php" ["line"]=> int(207) ["function"]=> string(6) "render" ["class"]=> string(30) "Zend\View\Renderer\PhpRenderer" ["type"]=> string(2) "->" } [2]=> array(5) { ["file"]=> string(74) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/View.php" ["line"]=> int(236) ["function"]=> string(6) "render" ["class"]=> string(14) "Zend\View\View" ["type"]=> string(2) "->" } [3]=> array(5) { ["file"]=> string(74) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/View.php" ["line"]=> int(200) ["function"]=> string(14) "renderChildren" ["class"]=> string(14) "Zend\View\View" ["type"]=> string(2) "->" } [4]=> array(5) { ["file"]=> string(103) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-mvc/src/View/Http/DefaultRenderingStrategy.php" ["line"]=> int(105) ["function"]=> string(6) "render" ["class"]=> string(14) "Zend\View\View" ["type"]=> string(2) "->" } [5]=> array(5) { ["file"]=> string(90) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-eventmanager/src/EventManager.php" ["line"]=> int(322) ["function"]=> string(6) "render" ["class"]=> string(43) "Zend\Mvc\View\Http\DefaultRenderingStrategy" ["type"]=> string(2) "->" } [6]=> array(5) { ["file"]=> string(90) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-eventmanager/src/EventManager.php" ["line"]=> int(171) ["function"]=> string(16) "triggerListeners" ["class"]=> string(30) "Zend\EventManager\EventManager" ["type"]=> string(2) "->" } [7]=> array(5) { ["file"]=> string(80) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-mvc/src/Application.php" ["line"]=> int(367) ["function"]=> string(12) "triggerEvent" ["class"]=> string(30) "Zend\EventManager\EventManager" ["type"]=> string(2) "->" } [8]=> array(5) { ["file"]=> string(80) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-mvc/src/Application.php" ["line"]=> int(348) ["function"]=> string(15) "completeRequest" ["class"]=> string(20) "Zend\Mvc\Application" ["type"]=> string(2) "->" } [9]=> array(5) { ["file"]=> string(47) "/var/www/heinrich.jens.vawi.de/public/index.php" ["line"]=> int(62) ["function"]=> string(3) "run" ["class"]=> string(20) "Zend\Mvc\Application" ["type"]=> string(2) "->" } }
我们所做的只是按照上面发布的教程... 不知道这个错误信息意味着什么<。< 还在寻找任何建议!!!
海因里希