RESTful API with yii 2.0.1

Hi:

I follow exactly step by step the guide doc-2.0/guide-rest-quick-start.html

  1. Create a basic template with

sudo composer create-project yiisoft/yii2-app-basic basic 2.0.1

  1. Create a database (mydata) with one table (mytable) in mysql

  2. Generate the model for mytable using gii

  3. Then follow the guide to create the controller

namespace app\controllers;

use yii\rest\ActiveController;

class MytableController extends ActiveController

{

public $modelClass = 'app\models\Mytable';

}

  1. 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’),

  1. 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

Problem solved!

I redo everything from scratch but this time use the guide "setup-restful-api-yii2" in http budiirawan.com

At first I got "500 Internal error"

Check error log file “.htaccess: Invalid command ‘RewriteEngine’,…”

fix

$ sudo a2enmod rewrite && sudo service apache2 restart

It works!