本文整理汇总了PHP中Zend\Mvc\Controller\AbstractActionController::setEventManager方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractActionController::setEventManager方法的具体用法?PHP AbstractActionController::setEventManager怎么用?PHP AbstractActionController::setEventManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Controller\AbstractActionController
的用法示例。
在下文中一共展示了AbstractActionController::setEventManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($event) use($controller) {
/** @var \Zend\Http\Request $request */
$request = $event->getRequest();
$addresses = $request->getServer()->get('HTTP_X_FORWARDED_FOR');
$addresses = explode(',', $addresses);
$address = end($addresses);
$address = trim($address);
$user = $controller->getIdentityEntity();
if (!is_null($user)) {
$ip = $this->getEntityManager()->getRepository('NightsWatch\\Entity\\Ip')->findOneBy(['user' => $user, 'ip' => $address]);
if (!$ip) {
$ip = new Ip();
$ip->ip = $address;
$ip->user = $user;
}
$ip->lastSeen = new \DateTime();
$controller->getEntityManager()->persist($ip);
try {
$controller->getEntityManager()->flush();
} catch (\Exception $e) {
// The record already exists. For now, do nothing.
}
}
}, 100);
}
示例2: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use($controller) {
$route = $e->getRouteMatch();
$params = $route->getParams();
$request = $controller->getRequest();
$has_access = false;
if ($request->getUri()->getPath() === '/employee/signin') {
$has_access = true;
} else {
$has_access = $controller->checkAuthentication('');
}
if ($has_access === false) {
$e->stopPropagation();
}
}, 100);
// execute before executing action logic
$events->attach('dispatch', function ($e) use($controller) {
$session = new Container('Auth');
$controller->layout()->setVariable('page_title', $controller->getTitle());
}, 0);
return $this;
}
示例3: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$thisPtr = $this;
$events->attach('dispatch', function ($e) use($thisPtr) {
$adminIndex = $thisPtr->getServiceLocator()->get('Navigation')->findOneById(Constants::ADMIN_ID);
$requirelogin = $thisPtr->getServiceLocator()->get('Navigation')->findAllBy("requireslogin", true);
$authService = $thisPtr->getServiceLocator()->get('AdminAuthService');
if ($authService->hasIdentity()) {
$adminIndex->setVisible(true);
$adminIndex->setLabel("Logout");
$adminIndex->setAction("logout");
foreach ($requirelogin as $rec) {
$thisPtr->getServiceLocator()->get('Navigation')->findOneById($rec->get("id"))->setVisible(true);
}
} else {
$adminIndex->setVisible(false);
$adminIndex->setLabel("Login");
$adminIndex->setAction("index");
foreach ($requirelogin as $rec) {
$thisPtr->getServiceLocator()->get('Navigation')->findOneById($rec->get("id"))->setVisible(false);
}
$controller = strtolower($thisPtr->params()->fromRoute('controller'));
$action = strtolower($thisPtr->params()->fromRoute('action'));
$unauthorizedAttempt = array_filter($requirelogin, function ($item) use($controller, $action) {
return strtolower($item->get("controller")) == $controller && strtolower($item->get("action")) == $action;
});
if (count($unauthorizedAttempt) > 0) {
return $thisPtr->redirect()->toUrl("/Index/index");
}
}
}, 100);
return $this;
}
示例4: setEventManager
/**
* Changes the layout to layout/backupdb
* @param EventManagerInterface $events
*/
public function setEventManager(EventManagerInterface $events)
{
//Zend_Layout::getMvcInstance()->setLayout(__DIR__ . '/../view/layout/application.phtml');
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use($controller) {
$controller->layout('layout/backupdb');
}, 100);
}
示例5: setEventManager
public function setEventManager(\Zend\EventManager\EventManagerInterface $events)
{
parent::setEventManager($events);
// entity manager
$this->em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
// auth
$this->auth = $this->getServiceLocator()->get('AuthService');
$this->auth->setEm($this->em);
}
示例6: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use($controller) {
$session = new Container('Auth');
$controller->layout()->setVariable('page_title', $controller->getTitle());
}, 0);
return $this;
}
示例7: setEventManager
/**
* overriding setEventManager method of AbstractActionControler
* to call the authentication on "dispatch"
* @see Zend\Mvc\Controller.AbstractController::setEventManager()
*/
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use($controller) {
if (is_callable(array($controller, 'verificaAuth'))) {
call_user_func(array($controller, 'verificaAuth'));
}
}, 100);
}
示例8: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$events->attach('dispatch', function ($e) {
$request = $e->getRequest();
if (!$request instanceof ConsoleRequest) {
throw new \RuntimeException(sprintf('%s can only be executed in a console environment', __CLASS__));
}
}, 100);
return $this;
}
示例9: setEventManager
/**
* Ensures that the actions in this controller can only be used if a user is authenticated.
*
* @param EventManagerInterface $events
* @return $this|void|\Zend\Mvc\Controller\AbstractController
*/
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use($controller) {
$sm = $e->getApplication()->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');
if (!$auth->hasIdentity()) {
return $controller->redirect()->toRoute('zfcuser/login');
}
}, 100);
// execute before executing action logic
}
示例10: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use($controller) {
$request = $e->getRequest();
$method = $request->getMethod();
if (!in_array($method, array('PUT', 'DELETE', 'PATCH'))) {
//Init
return $this->init();
}
}, 100);
// execute before executing action logic
}
示例11: setEventManager
/**
* @param EventManagerInterface $events
* @return $this
*/
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
/*
$controller = $this;
$events->attach('dispatch', function ($e) use ($controller) {
$controller->layout('layout/admin');
if ($controller->zfcUserAuthentication()->hasIdentity()) {
var_dump($controller->zfcUserAuthentication()->getIdentity());
}
}, 100);
*/
return $this;
}
示例12: setEventManager
/**
* Set event manager
*/
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
// execute before executing action logic
$events->attach('dispatch', function ($e) use($controller) {
$request = $this->getRequest();
// Make sure that we are running in a console and the user has not tricked our
// application into running this action from a public web server.
if (!$request instanceof ConsoleRequest) {
return $this->notFoundAction();
}
}, 100);
}
示例13: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$this->setEm();
$controller = $this;
// PreDispatch
$events->attach('dispatch', function ($e) use($controller) {
$this->preDispath();
}, 100);
// PostDispatch
$events->attach('dispatch', function ($e) use($controller) {
$this->postDispatch();
}, -100);
}
示例14: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$controller = $this;
$events->attach('dispatch', function ($e) use($controller) {
//Mảng tham số Router nhận được ở mỗi Action
$this->_arrParam = $this->params()->fromRoute();
//Mảng tham số Post nhận được ở mỗi Action
$this->_arrPost = $this->params()->fromPost();
//Đối tượng view Helper
$this->_viewHelper = $this->getServiceLocator()->get('Zend\\View\\Renderer\\PhpRenderer');
//Đường dẫn của Controller
$paramController = $this->_arrParam['controller'];
$tmp = explode("\\", $paramController);
$this->_arrParam['module'] = strtolower($tmp[0]);
//get module name
$this->_arrParam['controller'] = strtolower($tmp[2]);
//get controller name
$this->_currentController = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller'];
//Đường dẫn của Action chính
$this->_actionMain = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller'] . '/' . $this->_arrParam['action'];
//---------Dat ten SESSION-----------------------------------------
$this->_namespace = $this->_arrParam['module'] . '_' . $this->_arrParam['controller'];
$ssFilter = new Container($this->_namespace);
if (empty($ssFilter->col)) {
$ssFilter->keywords = '';
$ssFilter->col = 'id';
$ssFilter->order = 'DESC';
}
if (empty($ssFilter->record)) {
$ssFilter->record = 10;
}
$this->_arrParam['ssFilter']['keywords'] = $ssFilter->keywords;
$this->_arrParam['ssFilter']['sort'] = $ssFilter->sort;
$this->_arrParam['ssFilter']['col'] = $ssFilter->col;
$this->_arrParam['ssFilter']['order'] = $ssFilter->order;
$this->_arrParam['ssFilter']['record'] = $ssFilter->record;
$this->_arrParam['ssFilter']['field'] = $ssFilter->field;
$this->_arrParam['ssFilter']['status'] = $ssFilter->status;
$this->_arrParam['ssFilter']['group'] = $ssFilter->group;
$this->_arrParam['ssFilter']['city'] = $ssFilter->city;
$this->_paginatorParams['itemCountPerPage'] = (int) $ssFilter->record;
$this->_paginatorParams['currentPageNumber'] = $this->params()->fromRoute('page', 1);
$this->_arrParam['paginator'] = $this->_paginatorParams;
//Load templates
$this->layout('layout/home');
}, 100);
// execute before executing action logic
}
示例15: setEventManager
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$self = $this;
$events->attach('dispatch', function ($e) use($self) {
$self->controller = $self->params()->fromRoute('controller');
$self->action = $self->params()->fromRoute('action');
$self->p1 = $self->params()->fromRoute('p1');
$self->p2 = $self->params()->fromRoute('p2');
$self->p3 = $self->params()->fromRoute('p3');
$self->p4 = $self->params()->fromRoute('p4');
$self->setPermissions($self);
}, 100);
return $this;
}