Not found for extra Rest controller

Hi

I have the following set up as a rest module. The initial reports controller has always worked great, but I just tried to add another. I updated my Web file.

Web.php

// API rules go here
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => ['api/reports'],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => ['api/vue-ajax-reqs'],
                ],

The controller looks like:

<?php

namespace app\modules\api\controllers;
use yii\rest\ActiveController;

use app\models\ccasper\Site;

class VueAjaxReqs extends ActiveController
{   
    public function actionGetSites()
    {
        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        return Site::find()->all();
    }
}

And the module.php file looks like:

class Module extends \yii\base\Module
{
    public $defaultController = 'report';
    /**
     * @inheritdoc
     */
    public $controllerNamespace = 'app\modules\api\controllers';

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
        // http://www.yiiframework.com/doc-2.0/guide-rest-authentication.html
        \Yii::$app->user->enableSession = false;
        \Yii::$app->user->loginUrl = null;
        \Yii::$app->user->identityClass = 'app\models\reporting\User';
    }
}

I always get 404 when I try to access the new API request route api/vue-ajax-reqs/get-sites. So not sure what I’ve done and how to fix this??

Shouldn’t it be VueAjaxReqsController instead?

2 Likes

Ha!

Totally missed that. Thanks

1 Like