Advertisement
Guest User

IndexController

a guest
May 6th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Zend Framework (http://framework.zend.com/)
  4.  *
  5.  * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
  6.  * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
  7.  * @license   http://framework.zend.com/license/new-bsd New BSD License
  8.  */
  9.  
  10. namespace Home\Controller;
  11.  
  12. use Zend\Mvc\Controller\AbstractActionController;
  13. use Zend\View\Model\ViewModel;
  14. use Zend\Session\Container;
  15.  
  16. class IndexController extends AbstractActionController
  17. {
  18.     protected $headerView;
  19.     protected $registrationView;
  20.     protected $contentView;
  21.     protected $footerView;
  22.    
  23.     protected $lang;
  24.    
  25.     public function __construct()
  26.     {                      
  27.         //Initiate user session named 'user';
  28.         if(!isset($_SESSION['user']))
  29.             $session = new Container('user');
  30.        
  31.         //Content/Bodyview
  32.         $this->contentView = new ViewModel();
  33.        
  34.         //Headerview
  35.         $this->headerView = new ViewModel();
  36.         $this->headerView->setTemplate('general/header/loggedout');
  37.         $this->contentView->addChild($this->headerView, 'header');
  38.  
  39.         //Headerview
  40.         $this->registrationView = new ViewModel();
  41.         $this->registrationView->setTemplate('general/registration');
  42.         $this->contentView->addChild($this->registrationView, 'registrationWizard');
  43.        
  44.         //Footerview
  45.         $this->footerView = new ViewModel();
  46.         $this->footerView->setTemplate('general/footer');
  47.         $this->contentView->addChild($this->footerView, 'footer');     
  48.        
  49.         //Dependencies
  50.         $this->dependenciesJs = new ViewModel();
  51.         $this->dependenciesJs->setTemplate('general/dependencies_js');
  52.         $this->contentView->addChild($this->dependenciesJs, 'dependencies_js');
  53.        
  54.         $this->setLang();
  55.     }
  56.    
  57.     public function indexAction()
  58.     {      
  59.         $this->headerView->setTemplate('general/header/loggedout');
  60.        
  61.         //Check if user is logged in and set header accordingly
  62.         if($this->isLoggedIn())
  63.         {
  64.             $this->headerView->setTemplate('general/header/loggedin');
  65.         }
  66.        
  67.         if($this->params()->fromRoute('lang') == "")
  68.         {
  69.             return $this->redirect()->toRoute('home', array('lang' => $this->lang));
  70.         }
  71.        
  72.         return $this->contentView;     
  73.     }
  74.    
  75.     private function isLoggedIn()
  76.     {
  77.         if(isset($_SESSION['user']))
  78.         {
  79.             return true;
  80.         }
  81.          
  82.         return false;
  83.     }
  84.    
  85.     private function setLang()
  86.     {      
  87.         if(isset($_COOKIE['lang']) && $_COOKIE['lang'] != "")
  88.         {
  89.             $this->lang = $_COOKIE['lang'];
  90.         }
  91.         else
  92.         {          
  93.             $this->lang = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  94.         }      
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement