作者:sathishkumar
项目:ttitstes
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)) {
作者:2eye-studio
项目:developmen
/**
* 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;
}
作者:vfulc
项目:YAWI
/**
* (non-PHPdoc)
* @see \Zend\Mvc\Controller\AbstractActionController::onDispatch()
*/
public function onDispatch(MvcEvent $event)
{
$request = $event->getRequest();
if (!$request instanceof HttpRequest || !$request->isXmlHttpRequest()) {
//throw new \RuntimeException('This controller must only be called with ajax requests.');
}
return parent::onDispatch($event);
}
作者:webpant
项目:YAWI
/**
* 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;
}
作者:andreas-serl
项目:athene
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;
}
作者:argentinalui
项目:Learning-ZF
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);
}
作者:DEVOP-TEA
项目:3.0-Zen
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;
}
作者:socialo
项目:socialo
/**
* @param \Zend\Mvc\MvcEvent $e
*/
public function onDispatch(MvcEvent $e)
{
$layout = $this->layout();
$layout->setTemplate('default/layout');
$layout->bodyCls = '';
parent::onDispatch($e);
}
作者:nidhimanrt
项目:Zend-Sample-Cod
/**
* 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);
}
作者:binnguye
项目:kaffacoffe
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);
}
作者:rmukra
项目:ekda.or
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;
}
作者:hejame
项目:jTrMuzi
public function onDispatch(\Zend\Mvc\MvcEvent $e)
{
parent::onDispatch($e);
$routeMatch = $e->getRouteMatch();
$ar = $routeMatch->getParams();
// $this->accesslLog();
}
作者:codeline
项目:codelinerj
/**
* 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);
}
作者:totallydav
项目:auto-deplo
/**
* @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);
}
作者:nmnb1
项目:Aufri.co
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);
}
作者:mrkz
项目:kratos-finde
/**
* 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);
}
作者:augustoalves
项目:datawar
/**
* @param \Zend\Mvc\MvcEvent $e
* @return mixed
*/
public function onDispatch(MvcEvent $e, $validate = true)
{
if ($validate && !$this->getServiceLocator()->get('ServiceLocator')->hasIdentity()) {
$this->redirect()->toRoute(self::ROUTE_DEFAULT);
}
return parent::onDispatch($e);
}
作者:secretrepositor
项目:consultori
public function onDispatch(\Zend\Mvc\MvcEvent $e)
{
//$logged_block = array('index');
//if(!$this->identity() && !in_array($e->getRouteMatch()->getParam("action"), $logged_block)) return $this->redirect()->toRoute('home');
die("Em Manutenção.");
return parent::onDispatch($e);
}
作者:michelcandid
项目:zf2-doctrine-test
/**
* @param string $message
* @param string $router
* @param array $params
* @return \Zend\Mvc\Controller\AbstractController::redirect()->toRouter()
*/
public function redirect($message, $router, array $params = array())
{
if ($message) {
$this->flashMessenger()->addMessage($message);
}
return parent::redirect()->toRoute($router, $params);
}
作者:rwoverdij
项目:assetmanage
/**
* {@inheritdoc}
* @param RequestInterface $request
* @param ResponseInterface $response
* @return mixed|ResponseInterface
* @throws \RuntimeException
*/
public function dispatch(RequestInterface $request, ResponseInterface $response = null)
{
if (!$request instanceof ConsoleRequest) {
throw new \RuntimeException('You can use this controller only from a console!');
}
return parent::dispatch($request, $response);
}