我在module.php文件中有一个onBootstrap方法。我想使用此函数将用户日志详细信息存储到mysql数据库中。无法使用持久和刷新方法。有什么想法,如何创建数据库连接?
提前致谢
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->attach('finish', array($this, 'outputCompress'), 100);
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$app = $e->getApplication();
$sm = $app->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');
$routeMatch = $e->getRouteMatch();
// $name = $auth->getresolvedIdentity('id');
//echo "<pre>"; var_dump($auth); var_dump($routeMatch);
if($routeMatch && $auth){
$Userlog = new Userlog();
$Userlog->setUserid(10);
$Userlog->setUsername('abc');
$Userlog->setUrl_loaded('xyz');
$this->getObjectManager()->persist($Userlog);
$this->getObjectManager()->flush();
}