Skip to content

Commit 3733ef9

Browse files
committed
create functional add news in db
1 parent 74925a5 commit 3733ef9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

controllers/UserController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public function actionAdmin() {
2424
public function actionAdd() {
2525

2626
$model = new AddForm();
27+
2728
if ($model->load(Yii::$app->request->post())) {
28-
if ($model->validate()) {
29+
if ($model->save()) {
2930
Yii::$app->session->setFlash('success', 'Новость добавлена');
3031
return $this->refresh();
3132
} else {

models/AddForm.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace app\models;
44

5-
use yii\base\Model;
5+
use yii\db\ActiveRecord;
66

7-
class AddForm extends Model {
8-
public $title;
9-
public $text;
7+
class AddForm extends ActiveRecord {
8+
9+
public static function tableName() {
10+
return 'post';
11+
}
1012

1113
public function attributeLabels() {
1214
return [

0 commit comments

Comments
 (0)