08.13 php saved
olleolleolle
Tags add more
apps session  
Note
AppController method to run during beforeFilter(), to give "microsites" -- different styling to the website. Styling info is saved as an array in Session, under the key MicroSite.microsite
  1.     /**
  2.      * check the URL for 'microsite=kulturliv'.
  3.      *
  4.      * Set the microSite variables with Microsite data.
  5.      *
  6.      * @return void
  7.  
  8.      * @author Olle Jonsson
  9.      */
  10.     function _checkMicroSiteness() {
  11.         $microSiteName = requestValue('microsite', false);
  12.         if ($microSiteName === false) {
  13.             $microSiteData = $this->Session->read('MicroSite.microsite');
  14.         } else {
  15.             // Look up that keyname, and save it in Session, if successful
  16.             $db =& ConnectionManager::getDataSource('default');
  17.             $result = $db->one("SELECT * FROM microsites WHERE name = " . $db->value($microSiteName) . ";");
  18.             $microSiteData = arrayGet($result, 'microsites', false);
  19.             if (!empty($microSiteData)) {
  20.                 $this->Session->write('MicroSite.microsite', $microSiteData);
  21.             }
  22.         }
  23.         # Got nothing in QS and had nothing in Session.
  24.         #   OR
  25.         # Lookup of Microsite failed.
  26.         # ...so go to the "vanilla" website instead
  27.         if (empty($microSiteData)) {           
  28.             $this->_emptyMicrositeData();
  29.         } else {
  30.             $this->set('microSite', $microSiteData);
  31.         }
  32.     }
  33.  
  34.     function _emptyMicrositeData() {
  35.         $this->Session->del('MicroSite.microsite');
  36.         $this->set('microSite', array());
  37.     }
Parsed in 0.056 seconds, using GeSHi 1.0.7.14

Modify this Paste