I did it wrong, the request was written in the action method in the controller. How now to rewrite it so that the method itself was in the Content model, and in the actionAlbum controller it was called and rendered the view return $ this-> render ('album'). Somehow I did not find info on this topic

public function actionAlbum($id) { $query = Content::find() ->select('content.*') ->with('category') ->where(['category_id' => $id]); $pagination = new Pagination(['totalCount' => $query->count(), 'pageSize'=>6]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => $pagination ]); return $this->render('album', [ 'dataProvider' => $dataProvider, 'pagination' => $pagination, ]); } 

    1 answer 1

    Right or wrong, it's up to you to decide. Information on this topic will be roughly called - "How to make two methods in two classes and call another in one." The accuracy of the implementation will depend on the needs, a simple example:

    Model:

     class Content extends AcitveRecord{ ... public static function GetAlbum($id){ $query = Content::find(); .... return $var; } ... } 

    Controller:

     public function actionAlbum($id) { $data = Content::GetAlbum($id); ... return $this->render('album', [ 'data' => $data ]); }