コード例 #1
0
ファイル: blog.php プロジェクト: rkashapov2015/rinatk-yii
<?php

/* @var $this yii\web\View */
use app\models\Blog;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$post = \Yii::$app->request->post();
if (!empty($post)) {
    $blog = new Blog();
    $blog->name = $post['name_article'];
    $blog->body = $post['body_article'];
    $blog->date_create = date("y.m.d");
    $blog->author = '1';
    $blog->insert();
    Yii::$app->response->redirect(['main/blog']);
}
?>
<div class="Blog">
<h1>Блог</h1>
<div class="artcls">
<?php 
$articles = Blog::find()->orderBy('id')->all();
if (!empty($articles)) {
    echo "<ul>";
    foreach ($articles as $article) {
        echo "<li><p>" . $article['name'] . "</p><p>" . $article['body'] . "</p></li>";
    }
    echo "</ul>";
} else {
    echo "<p>Нет записей</p>";
}