cleric.test/models/CommentEditForm.php

33 lines
666 B
PHP

<?php
namespace app\models;
class CommentEditForm extends \yii\base\Model
{
public $id;
public $user_id;
public $content;
public function rules()
{
return [
[['content', 'id', 'user_id'], 'required'],
[['content'], 'string'],
[['id'], 'integer']
];
}
public function edit()
{
$comment = Comment::findOne([ 'id' => $this->id ]);
if ($comment === null) {
return false;
}
if ($comment->user_id !== $this->user_id) {
return false;
}
$comment->content = $this->content;
return $comment->save();
}
}