Example #1
0
 /**
  *
  *	This is used to narrow down results
  *
  *	@example only gather products from a specific category
  *			 $products = new Collection('tb_products', 'cat_id', $_GET['cat_id']);
  *
  *	@param string $table The name of the table this collection represents
  *	@param string $field The field to qualify which records are retrieved
  *	
  */
 public function get($modelType = null)
 {
     if (!is_null($modelType)) {
         $m = new $modelType();
         $this->table = $m->table;
     } else {
         if (!is_null($this->model)) {
             $m = new $this->model();
             $this->table = $m->table;
         }
     }
     $this->items = [];
     $this->db->select('*')->from($this->table);
     $q = $this->db->build_query();
     if (Model_Provider::has($q)) {
         $this->items = Model_Provider::get($q);
     } else {
         $this->items = $this->db->get();
         foreach ($this->items as $key => $item) {
             if (!is_null($modelType)) {
                 $model = new $modelType();
             } else {
                 if (!is_null($this->model)) {
                     $model = new $this->model();
                 } else {
                     $model = new Model($this->table, false);
                 }
             }
             $model->fill($item);
             $this->items[$key] = $model;
         }
         Model_Provider::set($q, $this->items);
     }
 }
 /**
  *
  *	This is used to narrow down results
  *
  *	@example only gather products from a specific category
  *			 $products = new Collection('tb_products', 'cat_id', $_GET['cat_id']);
  *
  *	@param string $table The name of the table this collection represents
  *	@param string $field The field to qualify which records are retrieved
  *	
  */
 public function get()
 {
     $this->items = [];
     $this->db->select('*')->from($this->table);
     $this->items = $this->db->get();
     foreach ($this->items as $key => $item) {
         $model = new Model($this->table, false);
         $model->fill($item);
         $this->items[$key] = $model;
     }
 }
Example #3
0
 /**
  * Test the Model::fill method with empty accessible array.
  *
  * @group laravel
  */
 public function testAttributesAreSetByFillMethodWithEmptyAccessible()
 {
     Model::$accessible = array();
     $array = array('name' => 'Taylor', 'age' => 25, 'foo' => 'bar');
     $model = new Model();
     $model->fill($array);
     $this->assertEquals(array(), $model->attributes);
     $this->assertNull($model->name);
     $this->assertNull($model->age);
     $this->assertNull($model->foo);
     Model::$accessible = null;
 }
Example #4
0
 /**
  * @param Model $model
  * @param array $data
  */
 protected function setModelData($model, array $data)
 {
     $model->fill($data);
 }