Yii2: No active controller is available in ActiveController

Created on 15 Sep 2016  路  11Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

I have a ActiveController. The default action work for crud but i have an extraPatterns and define it in my actions():

$actions['all'] = [
    'class' => All::class,
    'modelClass' => $this->modelClass,
    'checkAccess' => [$this, 'checkAccess'],
];

This error just occurred in all route not default crud actions.

Create url in my model with Url::to(['test/view', 'id' => 12], true)

What is the expected result?

Url should be created, I implement getLinks method in my model.

What do you get instead?

This Error:

"message": "Unable to resolve the relative route: test/view. No active controller is available.",

Additional info

| Q | A |
| --- | --- |
| Yii version | dev-master |
| PHP version | 5.6 |
| Operating system | Ubuntu 14.04 |

rest to be verified

All 11 comments

Url::to(['test/view', 'id' => 12], true)

use '/test/view' insetad of 'test/view'.

_This is an automated comment, triggered by adding the label question._

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.

Please use one of the above mentioned resources to discuss the problem.
If the result of the discussion turns out that there really is a bug in the framework, feel free to
come back and provide information on how to reproduce the issue. This issue will be closed for now.

@cebe Thank you. But this is not correctly create the url, Your solution created url is:

http://localhost/api/web/test/view?id=57da7cf054df560d2e10d191

But expected is this:

http://localhost/api/web/v1/test/57da7cf054df560d2e10d191

I used module for my rest services.

When i use default rest action the url correctly create like an index or view action.

@jafaripur
show your url rules and extraPaterns

[
    'class' => \yii\rest\UrlRule::class,
    'controller' => 'v1/test',
    'pluralize' => false,
    'tokens' => [
        '{id}' => '<id:\\w+>'
    ],
    'extraPatterns' => [
        'GET all' => 'all',
        'OPTIONS all' => 'options',
    ],
],

The problem is just exist in all route.

This error just occurred in all route not default crud actions.
The problem is just exist in all route.

IMO this issue is come from your All class not from yii

All route class is a normal action and extend from yii\rest\Action and similar to rest default view route yii\rest\ViewAction

@jafaripur could you check whether this issue has been fixed in YIi 2.0.10?

related to #12795

@cebe Yes, It's fixed.

Great, thanks for the feedback!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AstRonin picture AstRonin  路  3Comments

MUTOgen picture MUTOgen  路  3Comments

skcn022 picture skcn022  路  3Comments

kminooie picture kminooie  路  3Comments

sobit picture sobit  路  3Comments