【发布时间】:2013-10-28 15:34:44
【问题描述】:
我需要帮助。我想在控制器的动作运行之前在 Zend Framework 2 中运行一个方法。我将我的方法放在 Module.php 的 onBootstrap 中,但它在操作启动之前没有运行。
在 Module.php 中:
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$app = $e->getApplication();
$em = $app->getEventManager();
$em->attach(MvcEvent::EVENT_DISPATCH, function($e) {
$controller = $e->getTarget();
$controller->Init();
});
}
我想对我的适配器运行 Init() 方法,它将在操作运行之前初始化,但它不起作用,我总是收到以下消息:
可捕获的致命错误:参数 1 传递给 Application\ Model\Members::__construct() 必须是 Zend\Db\Adapter\Adapter 的实例,给定 null,在第 39 行的 PATH\module\Application\src\Application\Controller\AdminController.php 中调用并在 PATH\module 中定义\Application\src\Application\Model\Members.php 第 17 行
成员类在应该运行的动作中,它的 __construct 需要有一个有效的 Adapter 对象,应该在 Init() 方法中初始化。
谁能帮帮我? 非常感谢!
【问题讨论】:
标签: php zend-framework2