Example #1
0
 /**
  *  Initializes the controller with sanitized http request data,
  *  generates a token to be used to ensure that the next request is valid,
  *  and loads a user object if a valid session is found.
  *
  *  @access protected
  *  @return void
  */
 protected function _init()
 {
     parent::_init();
     $session = $this->_config['classes']['session'];
     $this->_session = new $session();
     $this->_http_get = $this->sanitize($this->_config['http_get']);
     $this->_http_post = $this->sanitize($this->_config['http_post']);
     if (!$this->_is_valid_request($this->_http_get) || !$this->_is_valid_request($this->_http_post)) {
         $this->handle_CSRF();
         $this->_token = null;
     }
     if (is_null($this->_token)) {
         $this->_token = Auth::create_token();
     }
     if ($this->_session->is_logged_in()) {
         $user = $this->_config['classes']['user'];
         $this->_user = new $user(array('id' => $this->_session->get_user_id()));
         $this->_template = $this->_user->get_template();
     }
 }
Example #2
0
 /**
  *  Initializes an object.  Object properties are populated
  *  automatically - first by checking the cache, and then, if that
  *  fails, by retrieving the values from the database.
  *
  *  @see /nx/core/Model->__construct()
  *  @access protected
  *  @return void
  */
 protected function _init()
 {
     parent::_init();
     $this->_db = Connections::get_db($this->_config['db']);
     $this->_cache = Connections::get_cache($this->_config['cache']);
     if (isset($this->_config['where'])) {
         $field = '`' . $this->_meta['key'] . '`';
         $table = $this->classname();
         $this->_db->find($field, $table, $this->_config['where'], 'LIMIT 1');
         $result = $this->_db->fetch('assoc');
         if ($result) {
             $this->_config['id'] = $result[$this->_meta['key']];
         }
     }
     if (is_numeric($this->_config['id'])) {
         if (!$this->pull_from_cache($this, $this->_config['id'])) {
             $where = array($this->_meta['key'] => $this->_config['id']);
             $this->_db->find('*', $this->classname(), $where);
             $this->_db->fetch('into', $this);
             $this->cache();
         }
     }
 }