ofilin/yii2-fillmodel

使用会话从最后保存的模型填充模型

安装: 0

依赖项: 0

建议者: 0

安全性: 0

星星: 0

关注者: 0

分支: 0

开放性问题: 0

类型:yii2-extension

0.1.0 2019-07-15 08:43 UTC

This package is auto-updated.

Last update: 2024-09-15 21:12:36 UTC


README

自动用最后保存的模型填充新模型的属性。

最后存储在会话中的属性

安装

将包添加到您的 composer.json

{
    "require": {
        "ofilin/yii2-fillmodel": "^0.1"
    }
}

并运行 composer update 或另外运行 composer require ofilin/yii2-fillmodel:^0.1

使用方法

在动作创建中,添加 Fill::model($model, ['attribute_1', 'attribute_2', 'attribute_3']);

public function actionCreate()
{
    $model = new Posts();
    
    // Add this line:
    \ofilin\fillmodel\Fill::model($model, ['groups', 'scheduled_date', 'scheduled_time']);

    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        return $this->redirect(['index']);
    }
    return $this->render('create', [
        'model' => $model,
    ]);
}