Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Zend Framework (http://framework.zend.com/)
- *
- * @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
- * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- namespace Home\Controller;
- use Zend\Mvc\Controller\AbstractActionController;
- use Zend\View\Model\ViewModel;
- use Zend\Session\Container;
- class IndexController extends AbstractActionController
- {
- protected $headerView;
- protected $registrationView;
- protected $contentView;
- protected $footerView;
- protected $lang;
- public function __construct()
- {
- //Initiate user session named 'user';
- if(!isset($_SESSION['user']))
- $session = new Container('user');
- //Content/Bodyview
- $this->contentView = new ViewModel();
- //Headerview
- $this->headerView = new ViewModel();
- $this->headerView->setTemplate('general/header/loggedout');
- $this->contentView->addChild($this->headerView, 'header');
- //Headerview
- $this->registrationView = new ViewModel();
- $this->registrationView->setTemplate('general/registration');
- $this->contentView->addChild($this->registrationView, 'registrationWizard');
- //Footerview
- $this->footerView = new ViewModel();
- $this->footerView->setTemplate('general/footer');
- $this->contentView->addChild($this->footerView, 'footer');
- //Dependencies
- $this->dependenciesJs = new ViewModel();
- $this->dependenciesJs->setTemplate('general/dependencies_js');
- $this->contentView->addChild($this->dependenciesJs, 'dependencies_js');
- $this->setLang();
- }
- public function indexAction()
- {
- $this->headerView->setTemplate('general/header/loggedout');
- //Check if user is logged in and set header accordingly
- if($this->isLoggedIn())
- {
- $this->headerView->setTemplate('general/header/loggedin');
- }
- if($this->params()->fromRoute('lang') == "")
- {
- return $this->redirect()->toRoute('home', array('lang' => $this->lang));
- }
- return $this->contentView;
- }
- private function isLoggedIn()
- {
- if(isset($_SESSION['user']))
- {
- return true;
- }
- return false;
- }
- private function setLang()
- {
- if(isset($_COOKIE['lang']) && $_COOKIE['lang'] != "")
- {
- $this->lang = $_COOKIE['lang'];
- }
- else
- {
- $this->lang = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement