====== DB: Abfragen ======
// return a single customer whose ID is 123
// SELECT * FROM `customer` WHERE `id` = 123
$customer = Customer::find()
->where(['id' => 123])
->one();
// return all active customers and order them by their IDs
// SELECT * FROM `customer` WHERE `status` = 1 ORDER BY `id`
$customers = Customer::find()
->where(['status' => Customer::STATUS_ACTIVE])
->orderBy('id')
->all();
// mit 2 Order-By:
$model::find()->orderBy([
'id_date' => SORT_DESC,
'item_no'=>SORT_ASC
]);
// return the number of active customers
// SELECT COUNT(*) FROM `customer` WHERE `status` = 1
$count = Customer::find()
->where(['status' => Customer::STATUS_ACTIVE])
->count();
// return all active customers in an array indexed by customer IDs
// SELECT * FROM `customer`
$customers = Customer::find()
->indexBy('id')
->all();
// Grösser/kleiner als
return Country::find()
->where(['>=', 'population', $lower])
->andWhere(['<=', 'population', $upper])
->all();
====== Select für Dropdown ======
$items = ArrayHelper::map(Datatables::find()->select(['datatable_id', 'datatable_name'])->asArray()->all(), 'datatable_id', 'datatable_name');
echo $form->field($model, 'datatable_id')->dropdownList($items,
['prompt'=>'...']
);
===== Eager Loading =====
$player = PlayersModel::find()->where(['id' => $id])->with('club')->one();
$class = Classes::find()->where(['id' => $class_id])->with('dancesClasses', 'dancesClasses.dances')->one();