Gc\Mvc\Controller\Action::construct PHP Method

construct() protected method

Constructor
protected construct ( ) : Zend\Http\Response | null
return Zend\Http\Response | null
    protected function construct()
    {
        $routeName = $this->getRouteMatch()->getMatchedRouteName();
        /**
         * Installation check, and check on removal of the install directory.
         */
        $config = $this->getServiceLocator()->get('Config');
        if (!isset($config['db']) and !in_array($routeName, $this->installerRoutes)) {
            return $this->redirect()->toRoute('install');
        } elseif (!in_array($routeName, $this->installerRoutes)) {
            $auth = $this->getServiceLocator()->get('Auth');
            if (!$auth->hasIdentity()) {
                if (!in_array($routeName, array('config/user/login', 'config/user/forgot-password', 'config/user/forgot-password-key', 'cms'))) {
                    return $this->redirect()->toRoute('config/user/login', array('redirect' => base64_encode($this->getRequest()->getRequestUri())));
                }
            } else {
                if (!in_array($routeName, array('config/user/forbidden', 'config/user/logout'))) {
                    $resultResponse = $this->checkAcl($auth->getIdentity());
                    if (!empty($resultResponse)) {
                        return $resultResponse;
                    }
                }
            }
        }
        $this->layout()->setVariable('routeParams', $this->getRouteMatch()->getParams());
        $this->layout()->setVariable('version', \Gc\Version::VERSION);
        $this->useFlashMessenger(false);
    }

Usage Example

Example #1
0
 /**
  * Constructor initiliaze module menu
  *
  * @return \Zend\Http\Response|null
  */
 protected function construct()
 {
     $result = parent::construct();
     if (!empty($result)) {
         return $result;
     }
     $routeParams = $this->layout()->getVariable('routeParams');
     $routeParams['module'] = 'gcmodule';
     $this->layout()->setVariable('routeParams', $routeParams);
 }