本文整理匯總了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]);
}