示例#1
0
文件: Model.php 项目: nbeletsky/nx
 /**
  *  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();
         }
     }
 }
示例#2
0
文件: db.php 项目: nbeletsky/nx
<?php

$dev = array('plugin' => 'PDO_MySQL', 'database' => '', 'host' => 'localhost', 'username' => 'root', 'password' => 'admin');
/*
$qa = array(
    'plugin'   => 'PDO_MySQL',
    'database' => '',
    'host'     => 'localhost',
    'username' => 'root',
    'password' => 'admin'
);

$ci = array(
    'plugin'   => 'PDO_MySQL',
    'database' => '',
    'host'     => 'localhost',
    'username' => 'root',
    'password' => 'admin'
);

$live = array(
    'plugin'   => 'PDO_MySQL',
    'database' => '',
    'host'     => 'localhost',
    'username' => 'root',
    'password' => 'admin'
);
*/
\nx\lib\Connections::add_db('default', $dev);
示例#3
0
文件: cache.php 项目: nbeletsky/nx
<?php

$dev = array('plugin' => 'Memcached', 'host' => 'localhost', 'persistent_id' => '');
/*
$qa = array(
    'plugin'        => 'Memcached',
    'host'          => 'localhost',
    'persistent_id' => ''
);

$ci = array(
    'plugin'        => 'Memcached',
    'host'          => 'localhost',
    'persistent_id' => ''
);

$live = array(
    'plugin'        => 'Memcached',
    'host'          => 'localhost',
    'persistent_id' => ''
);
*/
\nx\lib\Connections::add_cache('default', $dev);