本文整理汇总了PHP中Zend\Mvc\Controller\AbstractActionController类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractActionController类的具体用法?PHP AbstractActionController怎么用?PHP AbstractActionController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractActionController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onDispatch
use Zend\Barcode\Barcode;
//added by Yesh
class UserController extends AbstractActionController
{
protected $em;
protected $authservice;
public function onDispatch(MvcEvent $e)
{
/* Set Default layout for all the actions */
$this->layout('layout/layout');
$em = $this->getEntityManager();
$cities = $em->getRepository('\\Admin\\Entity\\City')->findBy(array('countryId' => 2));
$categories = $em->getRepository('\\Admin\\Entity\\Categories')->findBy(array('status' => 1));
$this->layout()->cities = $cities;
$this->layout()->categories = $categories;
$user_session = new Container('user');
$userid = $user_session->userId;
if (empty($userid)) {
return $this->redirect()->toRoute('home');
} else {
$msg = 'You are already logged in.';
$status = 1;
$this->layout()->setVariable('userId', $user_session->userId);
$this->layout()->setVariable('username', $user_session->userName);
$username = $user_session->userName;
$tmp_user = $em->getRepository('\\Admin\\Entity\\Users')->find($user_session->userId);
$city = $tmp_user->getCity();
if (!empty($city)) {
示例2: __invoke
/**
* Run an action from the specified controller and render it's associated template or view model
* @param string $expr
* @param array $attributes
* @param array $options
* @return string
*/
public function __invoke($expr, $attributes, $options)
{
$serviceManager = $this->serviceLocator;
$application = $serviceManager->get('Application');
//parse the name of the controller, action and template directory that should be used
$params = explode(':', $expr);
$controllerName = $params[0];
$actionName = 'not-found';
if (isset($params[1])) {
$actionName = $params[1];
}
//instantiate the controller based on the given name
$controller = $serviceManager->get('ControllerLoader')->get($controllerName);
//clone the MvcEvent and route and update them with the provided parameters
$event = $application->getMvcEvent();
$routeMatch = clone $event->getRouteMatch();
$event = clone $event;
$event->setTarget($controller);
$routeMatch->setParam('action', $actionName);
foreach ($attributes as $key => $value) {
$routeMatch->setParam($key, $value);
}
$event->setRouteMatch($routeMatch);
$actionName = $routeMatch->getParam('action');
//inject the new event into the controller
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($event);
}
//test if the action exists in the controller and change it to not-found if missing
$method = AbstractActionController::getMethodFromAction($actionName);
if (!method_exists($controller, $method)) {
$method = 'notFoundAction';
$actionName = 'not-found';
}
//call the method on the controller
$response = $controller->{$method}();
//if the result is an instance of the Response class return it
if ($response instanceof Response) {
return $response->getBody();
}
//if the response is an instance of ViewModel then render that one
if ($response instanceof ModelInterface) {
$viewModel = $response;
} elseif ($response === null || is_array($response) || $response instanceof \ArrayAccess || $response instanceof \Traversable) {
$viewModel = new ViewModel($response);
} else {
return '';
}
//inject the view model into the MVC event
$event->setResult($viewModel);
//inject template name based on the matched route
$injectTemplateListener = new InjectTemplateListener();
$injectTemplateListener->injectTemplate($event);
$viewModel->terminate();
$viewModel->setOption('has_parent', true);
//render the view model
$view = $serviceManager->get('Zend\\View\\View');
$output = $view->render($viewModel);
return $output;
}
示例3: getResponseHeader
/**
* Get response header by key
*
* @param string $header
*
* @return \Zend\Http\Header\HeaderInterface|false
*/
protected function getResponseHeader($header)
{
/** @var Response $response */
$response = $this->controller->getResponse();
$headers = $response->getHeaders();
$responseHeader = $headers->get($header, false);
return $responseHeader;
}
示例4: preparePluginManager
protected function preparePluginManager()
{
if ($this->controller->getPluginManager() instanceof \PHPUnit_Framework_MockObject_MockObject) {
return $this->controller->getPluginManager();
}
$pluginManager = $this->getMock('Zend\\Mvc\\Controller\\PluginManager');
$this->controller->setPluginManager($pluginManager);
return $pluginManager;
}
示例5: setup
public function setup()
{
parent::setup();
$this->controller = new $this->controllerFQDN();
$this->request = new Request();
$this->routeMatch = new RouteMatch(array('router' => array('routes' => array($this->controllerRoute => $this->routes[$this->controllerRoute]))));
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
$this->controller->setServiceLocator($this->serviceManager);
}
示例6: 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;
}
示例7: onDispatch
/**
* @param \Zend\Mvc\MvcEvent $e
*/
public function onDispatch(MvcEvent $e)
{
$layout = $this->layout();
$layout->setTemplate('default/layout');
$layout->bodyCls = '';
parent::onDispatch($e);
}
示例8: onDispatch
/**
* check if the admin is login otherwise redirect it to login page
**/
public function onDispatch(\Zend\Mvc\MvcEvent $e)
{
if (!isset($this->container->admin_id)) {
return $this->redirect()->toRoute('adminlogin');
}
return parent::onDispatch($e);
}
示例9: onDispatch
public function onDispatch(\Zend\Mvc\MvcEvent $e)
{
$install = setupUtility::checkInstall();
if ($install == true) {
return $this->redirect()->toRoute('install');
}
//get doctrine service
$this->serviceLocatorStr = 'doctrine';
$this->sm = $this->getServiceLocator();
$this->doctrineService = $this->sm->get($this->serviceLocatorStr);
//get translate service
$this->translator = Utility::translate();
//check login
$user = Utility::checkLogin();
if (!is_object($user) && $user == 0) {
$this->redirect()->toRoute('frontend/child', array('controller' => 'login'));
}
//start acl
// $acl = new myAcl();
// $currentRoute = $this->getModuleCurrentRoute($e);
// $isOk = $acl->checkRole(UtilityRoleLevel::convertUserTypeToRole($user->userType)['role'],$currentRoute);
// if(!$isOk || $isOk == '' || $isOk == null){
// return $this->redirect()->toRoute('frontend/child', array('controller' => 'login'));
// }
//end check login
//end acl
$this->init();
return parent::onDispatch($e);
}
示例10: 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;
}
示例11: onDispatch
public function onDispatch(\Zend\Mvc\MvcEvent $e)
{
parent::onDispatch($e);
$routeMatch = $e->getRouteMatch();
$ar = $routeMatch->getParams();
// $this->accesslLog();
}
示例12: attachDefaultListeners
/**
* Register the default events for this controller
*
* @return void
*/
protected function attachDefaultListeners()
{
parent::attachDefaultListeners();
$events = $this->getEventManager();
$events->attach('dispatch', array($this, 'initJsController'), -10);
$events->attach('dispatch', array($this->getJsLoader(), 'onMvcDispatch'), -90);
}
示例13: onDispatch
/**
* @param MvcEvent $event
*
* @return parent::onDispatch
*/
public function onDispatch(MvcEvent $event)
{
$request = $event->getRequest();
$remoteAddr = $request->getServer('REMOTE_ADDR');
// check IP address is allowed
$application = $event->getApplication();
$config = $application->getConfig();
$autoDeployConfig = $config['auto_deploy'];
$allowedIpAddresses = $autoDeployConfig['ipAddresses'];
// error if ip is not allowed
if (!in_array($remoteAddr, $allowedIpAddresses, true)) {
$baseModel = new \Zend\View\Model\ViewModel();
$baseModel->setTemplate('layout/output');
$model = new \Zend\View\Model\ViewModel();
$model->setTemplate('error/403');
$baseModel->addChild($model);
$baseModel->setTerminal(true);
$event->setViewModel($baseModel);
$response = $event->getResponse();
$response->setStatusCode(403);
$response->sendHeaders();
$event->setResponse($response);
exit;
}
return parent::onDispatch($event);
}
示例14: onDispatch
public function onDispatch(\Zend\Mvc\MvcEvent $event)
{
self::$instance = $this;
if (!isset($_COOKIE['language'])) {
$headers = $this->getRequest()->getHeaders();
$defaultLanguage = 'en';
$supportedLanguages = array('en', 'pl');
$match = false;
$this->setLanguage($defaultLanguage);
setcookie('language', $this->getLanguage(), time() + 60 * 60 * 24 * 365, '/');
} else {
$this->setLanguage($_COOKIE['language']);
setcookie('language', $this->getLanguage(), time() + 60 * 60 * 24 * 365, '/');
}
$referer = $this->getRequest()->getHeader('Referer');
if ($referer) {
$referer = $referer->uri()->getPath();
} else {
$referer = '/';
}
$request = $this->getRequest();
$response = $this->getResponse();
if ($request->getHeaders()->get('Cookie') !== false && isset($request->getHeaders()->get('Cookie')->previous_link)) {
$this->setPreviousLink($request->getHeaders()->get('Cookie')->previous_link);
} else {
$cookie = new SetCookie('previous_link', $referer, time() + 3600);
$response->getHeaders()->addHeader($cookie);
$this->setPreviousLink($referer);
}
parent::onDispatch($event);
}
示例15: attachDefaultListeners
/**
* Se encarga de colgar las funciones predispatch y post dispatch para ser ejecutados
* antes y despues del controlador principal y poder realizar tareas comunes de
* inicializacion y post procesamiento
* @see \Zend\Mvc\Controller\AbstractController::attachDefaultListeners()
*/
protected function attachDefaultListeners()
{
parent::attachDefaultListeners();
$events = $this->getEventManager();
$events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'preDispatch'), 100);
$events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'postDispatch'), -100);
}