first commit
This commit is contained in:
43
app/FormModel/admin/news/NewsFormModel.php
Normal file
43
app/FormModel/admin/news/NewsFormModel.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\admin\news;
|
||||
|
||||
use App\Model\AppNews;
|
||||
|
||||
class NewsFormModel
|
||||
{
|
||||
|
||||
private array $attributes = [];
|
||||
|
||||
public function setAttributes(array $attr, $allowProp = [])
|
||||
{
|
||||
if (!$allowProp) {
|
||||
$this->attributes = $attr;
|
||||
}
|
||||
|
||||
foreach($allowProp as $prop) {
|
||||
if (isset($attr[$prop])) {
|
||||
$this->attributes[$prop] = $attr[$prop];
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function insert()
|
||||
{
|
||||
$model = new AppNews();
|
||||
$model->setRawAttributes($this->attributes);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$model = AppNews::find($this->attributes['id']);
|
||||
$model->title = $this->attributes['title'];
|
||||
$model->keywords = $this->attributes['keywords'];
|
||||
$model->description = $this->attributes['description'];
|
||||
$model->cover = $this->attributes['cover'];
|
||||
$model->content = $this->attributes['content'];
|
||||
$model->save();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user