Делал все на основе этой статьи:
ссылка
Но в логах пишет
Error: Class 'app\models\Country' not found in /home/artyom/www/localhost/controllers/CountryController.php:19
Мой Country.php
<?php
/**
* Created by PhpStorm.
* User: artyom
* Date: 09.08.17
* Time: 14:45
*/
namespace app\models;
use yii\db\ActiveRecord;
class Country extends ActiveRecord
{
}
Мой CountryController.php
<?php
/**
* Created by PhpStorm.
* User: artyom
* Date: 09.08.17
* Time: 14:48
*/
namespace app\controllers;
use yii\web\Controller;
use yii\data\Pagination;
use app\models\Country;
class CountryController extends Controller
{
public function actionIndex()
{
$query = Country::find();
$pagination = new Pagination([
'defaultPageSize' => 5,
'totalCount' => $query->count(),
]);
$countries = $query->orderBy('name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('index', [
'countries' => $countries,
'pagination' => $pagination,
]);
}
}
Мой файл в views/country/index.php
<?php
/**
* Created by PhpStorm.
* User: artyom
* Date: 09.08.17
* Time: 14:51
*/
use yii\helpers\Html;
use yii\widgets\LinkPager;
?>
<h1>Countries</h1>
<ul>
<?php foreach ($countries as $country): ?>
<li>
<?= Html::encode("{$country->name} ({$country->code})") ?>:
<?= $country->population ?>
</li>
<?php endforeach; ?>
</ul>
<?= LinkPager::widget(['pagination' => $pagination]) ?>
Может автолодеру нужно что-то сказать?