public function actionDelete() { // 删除已有客户记录 $world = World::findOne("1"); $world->delete(); // 删除多个年龄大于20,性别为男(Male)的客户记录 //World::deleteAll('age > :age AND gender = :gender', [':age' => 20, ':gender' => 'M']); }
public function db() { $queries = isset($this->request->query['queries']) ? $this->request->query['queries'] : 1; $worlds = array(); for ($i = 0; $i < $queries; ++$i) { $worlds[] = World::first(array('conditions' => array('id' => mt_rand(1, 10000)))); } return $this->render(array('json' => $worlds)); }
public function actionIndex() { World::updateAll(array('name' => 'Hello World!')); for ($i = 0; $i < 2; $i++) { $rnd = mt_rand(1, 10000); $result = World::findOne($rnd); } $result = World::findOne($result->id); return $result->name; }
/** * query ip division * @return null|string[] null or division array */ public function query() { if ($this->validate()) { $ip = ip2long($this->ip); $results = []; foreach (['full' => Full::className(), 'mini' => Mini::className(), 'china' => China::className(), 'world' => World::className()] as $name => $index) { $results[$name] = $this->getResultFromModel($index, $ip); } return $results; } return null; }
public function actionTest() { $var = new World(); echo $var->world(); $var = World::find()->where(["id" => 1])->one(); var_dump($var['id']); var_dump($var['user']); var_dump($var); //$command = $connection->createCommand('SELECT * FROM world'); //var_dump(World::model()->findByPk(1)); //var_dump($command); die; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = WorldModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'user', $this->user]); return $dataProvider; }
/** * @param $type * @return Full|Mini|China|World * @throws NotFoundHttpException */ protected function getIndexClass($type) { switch ($type) { case 'full': return Full::className(); case 'mini': return Mini::className(); case 'china': return China::className(); case 'world': return World::className(); default: throw new NotFoundHttpException("Type {$type} not found"); } }
/** * @return \yii\db\ActiveQuery */ public function getWorld() { return $this->getIndex(World::className()); }
/** * Finds the World model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return World the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = World::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }