P
P
po472021-01-26 21:36:28
Yii
po47, 2021-01-26 21:36:28

How to load views into yii "content" variable?

The question is as simple as possible, but I just can not understand what I'm doing wrong.
Created a new template in layout, added it to config/wep.php. All OK.

<?php

use yii\helpers\Html;
use app\assets\AppAsset;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrapper">
        <div class="container">
                <?= Html::a('Ссылка 1', ['post/index.php']) ?>
                <?= Html::a('Ссылка 2', ['admin/index.php']) ?>
        </div>
                <?= $content ?>
</div>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>


Next, we created new controllers in the Controllers folder
<?php

namespace app\controllers;

use yii\web\Controller;

class PostController extends Controller {
     
  public function actionPost()
    {
        return $this->render('index');
    }
}
?>


Added post and admin folders to the view folder with index.php files
Via phptest/web/index.php?r=post error:
"Not Found (#404)
Page not found.
The above error occurred while the Web server was processing your request Please contact us if you think this is a server error .
Thank you."

I understand that it does not find the folder with the view, but why? What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-01-26
@po47

In your case, the overgrowth will be like this:
http://phptest/web/index.php?r=post/post

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question