Ejemplo n.º 1
0
 /**
  * init the model
  */
 public function __construct()
 {
     $f3 = \Base::instance();
     $this->table = $f3->get('db_table_prefix') . $this->table;
     $this->db = 'DB';
     parent::__construct();
     // validation & error handler
     $class = get_called_class();
     // PHP 5.3 bug
     $saveHandler = function (\DB\Cortex $self) use($class) {
         $valid = true;
         foreach ($self->getFieldConfiguration() as $field => $conf) {
             if (isset($conf['type'])) {
                 $val = $self->get($field);
                 $model = strtolower(str_replace('\\', '.', $class));
                 // check required fields
                 if (isset($conf['required'])) {
                     $valid = \Validation::instance()->required($val, $field, 'error.' . $model . '.' . $field);
                 }
                 // check unique
                 if (isset($conf['unique'])) {
                     $valid = \Validation::instance()->unique($self, $val, $field, 'error.' . $model . '.' . $field);
                 }
                 if (!$valid) {
                     break;
                 }
             }
         }
         return $valid;
     };
     $this->beforesave($saveHandler);
 }
Ejemplo n.º 2
0
 public function __construct($db = NULL, $table = NULL, $fluid = NULL, $ttl = 0)
 {
     $this->addStaticFieldConfig();
     parent::__construct($db, $table, $fluid, $ttl);
     // insert events ------------------------------------------------------------------------------------
     $this->beforeinsert(function ($self, $pkeys) {
         return $self->beforeInsertEvent($self, $pkeys);
     });
     $this->afterinsert(function ($self, $pkeys) {
         $self->afterInsertEvent($self, $pkeys);
         $self->clearCacheData();
     });
     // update events ------------------------------------------------------------------------------------
     $this->beforeupdate(function ($self, $pkeys) {
         return $self->beforeUpdateEvent($self, $pkeys);
     });
     $this->afterupdate(function ($self, $pkeys) {
         $self->afterUpdateEvent($self, $pkeys);
         $self->clearCacheData();
     });
     // erase events -------------------------------------------------------------------------------------
     $this->beforeerase(function ($self, $pkeys) {
         return $self->beforeEraseEvent($self, $pkeys);
     });
     $this->aftererase(function ($self, $pkeys) {
         $self->afterEraseEvent($self, $pkeys);
     });
 }
Ejemplo n.º 3
0
 public function __construct($db = NULL, $table = NULL, $fluid = NULL, $ttl = 0)
 {
     $this->addStaticFieldConfig();
     parent::__construct($db, $table, $fluid, $ttl);
     // events -----------------------------------------
     $this->afterinsert(function ($self) {
         $self->clearCacheData();
     });
     // model updated
     $this->afterupdate(function ($self) {
         $self->clearCacheData();
     });
     // model updated
     $this->beforeinsert(function ($self) {
         $self->beforeInsertEvent($self);
     });
 }
Ejemplo n.º 4
0
 /**
  *  @see \DB\SQL\Mapper::__construct($db, $table, $ttl)
  */
 public function __construct($db, $table, $fluid = null, $ttl = 60)
 {
     parent::__construct($db, $table, $fluid, $ttl);
     $this->properties = array();
 }
Ejemplo n.º 5
0
 public function __construct()
 {
     $db = \Base::instance()->get('SQLDB');
     parent::__construct($db, 'manufacturer');
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     $this->fieldConf = array('author' => array('belongs-to-one' => '\\AuthorModel'), 'tags' => array('belongs-to-many' => '\\TagModel'), 'tags2' => array('has-many' => array('\\TagModel', 'news')));
     parent::__construct();
 }