Hi everyone
I’m ArklemX and I’m new using the Yii2 Framework.
I don’t really know where to put this Topic, so please give me a hint if necessary.
I have somewhat a problem.
I need to use both rest controllers ( to make an API ) and normal controllers ( for my web ) in the same application. But, the both of them will make basically the same work. So i wanted to know if it was possible to use the same controller for both web and api purposes.
For example,
i have a PostController which is a rest Controller.
And i want to use him to render a view in certain case.
<?php
namespace frontend\controllers;
use frontend\resource\Post;
use yii\filters\auth\HttpBearerAuth;
use yii\rest\ActiveController;
class PostController extends ActiveController
{
public $modelClass = Post::class;
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator']['only'] = ['create', 'update', 'delete'];
$behaviors['authenticator']['authMethods'] = [
HttpBearerAuth::class
];
return $behaviors;
}
public function actionIndex()
: string
{
return $this->render('index');
}
}
Is it possible ? If not, how can i do this in a simple way.
Thanks for your future responses .