P
P
Pios882018-07-13 22:13:30
Yii
Pios88, 2018-07-13 22:13:30

Why might ActiveController not work in Yii2?

There is a model:

namespace app\models;
use yii\db\ActiveRecord;

class Book extends ActiveRecord
{
    public static function tableName()
    {
       return 'book';
    }
    public static function primaryKey()
    {
        return ['id'];
    }
    public function getAuthor()
    {
        return $this->hasOne(Author::className(), ['id' => 'author_id']);
    }
}

It is connected to the Author model, but everything is fine here, the links work fine in other functionality.
I need to organize the issuance of data in json format via RESTful by a separate controller.
First, I turned to the documentation .
And I copied and pasted the code of the controller itself, replacing it with my name of the model and controller, the simplest one given in the documentation:
namespace app\controllers;
use yii\rest\ActiveController;

class BookController extends ActiveController
{
    public $modelClass = 'app\models\Book';
}

Added to 'urlManager': 'rules' =>
According to the documentation, this is enough to get the finished API (finishing is still a secondary issue). But in fact, both through curl and through restlet_client (Chrome extension) I get:
status: 500 and PHP Fatal Error Class app\controllers\ActiveController; not found
I can't even guess what's wrong. This situation has me confused. I made a request to other controllers through restlet_client and received 200 and the entire page code. That is, it's not about the tools 100%, something is wrong with the code. What are the options? Why is the standard 100% working example from the documentation suddenly not working? And where could be the mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question