Hi:
I follow exactly step by step the guide doc-2.0/guide-rest-quick-start.html
- Create a basic template with
sudo composer create-project yiisoft/yii2-app-basic basic 2.0.1
-
Create a database (mydata) with one table (mytable) in mysql
-
Generate the model for mytable using gii
-
Then follow the guide to create the controller
namespace app\controllers;
use yii\rest\ActiveController;
class MytableController extends ActiveController
{
public $modelClass = 'app\models\Mytable';
}
- Then add the urlManager configuration
‘urlManager’ => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'mytable'],
],
]
to the file config/web.php (at the end of the components, right after the line
‘db’ => require(DIR . ‘/db.php’),
- Enable JSON input by adding
‘parsers’ => [
'application/json' => 'yii\web\JsonParser',
]
into the component request in the file config/web.php
‘request’ => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'Mi6mIXmEdvG8Vw9tYe359IEGYOzhQZ7T',
‘parsers’ => [
'application/json' => 'yii\web\JsonParser',
]
],
Then I try
curl -i -H "Accept:application/json" "xxxxxxxxxx/mytable"
curl -i -H "Accept:application/json" "xxxxxxxxxx/mytables"
curl -i -H "Accept:application/json" "xxxxxxxxxx/web/mytable"
curl -i -H "Accept:application/json" "xxxxxxxxxx/web/mytables"
(since I can’t embed the link xxxxx is http: localhost basic
Nothing works! I receive the same message saying that the page does not exist
Please help, thank you very much
Andy