Skip to content

Commit 74925a5

Browse files
committed
create news list
1 parent cc8ad64 commit 74925a5

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

controllers/UserController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44

55
use yii\web\Controller;
66
use app\models\AddForm;
7+
use app\models\Category;
78
use Yii;
89

910
class UserController extends Controller {
1011

1112
public function actionIndex() {
12-
return $this->render('index');
13+
$cats = Category::find()->all();
14+
15+
return $this->render('index', compact('cats'));
1316
}
1417

1518
public function actionAdmin() {
16-
return $this->render('admin');
19+
$cats = Category::find()->all();
20+
21+
return $this->render('admin', compact('cats'));
1722
}
1823

1924
public function actionAdd() {

models/Category.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
use yii\db\ActiveRecord;
6+
7+
class Category extends ActiveRecord {
8+
9+
public static function tableName() {
10+
return 'post';
11+
}
12+
13+
}

views/user/add.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ul class="nav nav-pills">
99
<li role="presentation" class="active" ><?= Html::a('Новости', ['user/admin']) ?></li>
1010
<li role="presentation" class="active" id="choose" ><?= Html::a('Добавление новостей', ['user/add']) ?></li>
11-
<li role="presentation" class="active" ><?= Html::a('Удаление новостей', ['user/delete']) ?></li>
11+
<li role="presentation" class="active" ><?= Html::a('Редактирование и удаление новостей', ['user/delete']) ?></li>
1212
</ul>
1313
</div>
1414
</div>

views/user/admin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
<ul class="nav nav-pills">
88
<li role="presentation" class="active" id="choose"><?= Html::a('Новости', ['user/admin']) ?></li>
99
<li role="presentation" class="active" ><?= Html::a('Добавление новостей', ['user/add']) ?></li>
10-
<li role="presentation" class="active" ><?= Html::a('Удаление новостей', ['user/delete']) ?></li>
10+
<li role="presentation" class="active" ><?= Html::a('Редактирование и удаление новостей', ['user/delete']) ?></li>
1111
</ul>
1212
</div>
1313
</div>
14+
15+
<?php foreach ($cats as $cat) {
16+
echo '<h1>'.$cat->title.'<br></h1>';
17+
echo '<h3>'.$cat->text.'<br></h3><br><br>';
18+
} ?>

views/user/delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ul class="nav nav-pills">
88
<li role="presentation" class="active" ><?= Html::a('Новости', ['user/admin']) ?></li>
99
<li role="presentation" class="active" ><?= Html::a('Добавление новостей', ['user/add']) ?></li>
10-
<li role="presentation" class="active" id="choose" ><?= Html::a('Удаление новостей', ['user/delete']) ?></li>
10+
<li role="presentation" class="active" id="choose" ><?= Html::a('Редактирование и удаление новостей', ['user/delete']) ?></li>
1111
</ul>
1212
</div>
1313
</div>

views/user/index.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
<h1>Новости</h1>
1+
<div style="font-size: 50px; text-align: center">Новости<br><br></div>
2+
3+
<?php foreach ($cats as $cat) {
4+
echo '<h1>'.$cat->title.'<br></h1>';
5+
echo '<h3>'.$cat->text.'<br></h3><br><br>';
6+
} ?>

0 commit comments

Comments
 (0)