/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Fruits::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'weight' => $this->weight, 'somedata1' => $this->somedata1]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'color', $this->color]); return $dataProvider; }
public function getFruits() { return $this->hasMany(Fruits::className(), ['id' => 'id']); }
$fruitObject = Fruits::findOne(1); $fruitObject->updateCounters(['somedata1' => 1]); //SET somedata1 = samedata1 + 1 */ $fruit = Fruits::findOne(['name' => 'pineapple']); Fruits::getDb()->transaction(function ($db) use($fruit) { $fruit->somedata1 = 3; $fruit->save(); }); $fruitObject = Fruits::findOne(1); echo '<pre>'; print_r($fruitObject); echo '</pre>'; echo "<br>"; print_r($fruitObject->name); echo "<br>"; $fruitObject = Fruits::findAll(['color' => 'brown']); /* echo '<pre>'; print_r($fruitObject); echo '</pre>'; echo "<br>"; */ ?> <h4>fruits/second</h4> <p> You may change the content of this page by modifying the file <code><?php echo __FILE__; ?> </code>. </p>
/** * Finds the Fruits model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Fruits the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Fruits::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }