0

Without pretty url route has view http://192.168.100.5/index.php?r=tweet/statistic&from=20160320&to=20160325 and it`s work well.

As docs say when 'enablePrettyUrl' => true /tweet call default action - and it`s work well also

But for other actions route should be /tweet/statistic. But there is 404 error.

How i can call app\controllers\TweetController actionStatistic() in this case?

added: i use basic template

'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => true,
    'showScriptName' => false,
    'rules' => [
        ['class' => 'yii\rest\UrlRule',
         'controller' => 'tweet'],
        'GET tweet/statistic' => 'tweet/statistic'
    ],
],

when i try curl request for http://192.168.100.5/tweet/statistic

HTTP/1.1 404 Not Found

If 'enablePrettyUrl' => false and http://192.168.100.5/index.php?r=tweet/statistic" it`s work well

3
  • are you still on the REST api? as that changes things a lot. Commented Mar 30, 2016 at 22:35
  • have you defined the urlRule in application configuration ? see yiiframework.com/doc-2.0/yii-rest-urlrule.html Commented Mar 31, 2016 at 6:00
  • Yes i do, but it working only for default action. Commented Mar 31, 2016 at 6:41

1 Answer 1

1

Please mention that this is a rest API, as this changes things a lot. The point is you have to declare the rules so Yii2 will now know how to handle them. You have to tell it what type of request this will be and where the request will go. This is quite different compared to the normal application because this is a rest API.

My working config:

 'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => [
                        'v1/client',
..........................
                    ]
                ],
                'GET v1/clients/info' => 'v1/client/info',
                'POST v1/settings/suburb' => 'v1/setting/suburb',
            ],
        ],
Sign up to request clarification or add additional context in comments.

3 Comments

i add into my question my urlManger and still 404
Many thanks, your answer help me to where a made mistake)
Cool, as I was out of ideas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.