本文整理汇总了PHP中yii\base\Model::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getAttribute方法的具体用法?PHP Model::getAttribute怎么用?PHP Model::getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Model
的用法示例。
在下文中一共展示了Model::getAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: moveAfter
/**
* Move current model after another specified model (ie. `$model->moveAfter($another_model);`)
* Note: you must manually call refresh() on needed models
* @param \yii\base\Model $another_model Model taht would be before current model
*/
public function moveAfter($another_model)
{
$field = $this->attribute;
//! @todo Переписать эти два запроса на один, использующий CASE WHEN THEN
// shift sort_order field for current model and below
Yii::$app->db->createCommand("UPDATE " . $this->owner->tableName() . " SET {$field} = {$field} + 1 WHERE {$field} >= :model_sort_order", [':model_sort_order' => intval($another_model->getAttribute($field)) + 1])->execute();
// shift sort_order field for records upper current
Yii::$app->db->createCommand("UPDATE " . $this->owner->tableName() . " SET {$field} = {$field} - 1 WHERE {$field} <= :model_sort_order_lower AND {$field} >= :model_sort_order_upper", [':model_sort_order_lower' => intval($another_model->getAttribute($field)) + 1, ':model_sort_order_upper' => intval($this->owner->getAttribute($field))])->execute();
// change sort_order of our record
$this->owner->setAttribute($field, $another_model->getAttribute($field));
$this->owner->save(false, [$field]);
}