There is a table in the database with saved tweets.

There is a controller:

<?php namespace app\controllers; use yii\rest\ActiveController; class TweetController extends ActiveController { public $modelClass = 'app\models\Tweet'; } 

There is a corresponding model app\model\Tweet created in via gii .

Added to app\web\config :

 .............. 'components' => [ 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ ['class' => 'yii\rest\UrlRule', 'controller' => 'tweet'], ], ], 'request' => [ 'parsers' =>['application/json' => 'yii\web\JsonParser', ], ], ............... 

Added .htaccess to app\web according to http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html

app\web registered in apache DocumentRoot

According to the documentation: curl -i -H "Accept:application/json" "http://localhost/tweets" should return the pagination of the model data. Instead of this:

 HTTP/1.1 404 Not Found Date: Tue, 29 Mar 2016 14:04:05 GMT Server: Apache/2.4.7 (Ubuntu) Content-Length: 278 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /tweets was not found on this server.</p> <hr> <address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address> </body></html> 

I also tried the variant with urlManager 'controller' => ['tw' => 'tweet'] and the corresponding url.

Why gives 404 error? Powered by http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html

  • Try this: curl -X GET --header "Accept: application / json" " localhost / tweets ". Does the requested page open in a browser? - NPreston

0