I’m trying to learn about Rest, but in my test pluralizing seems doesn’t working.
This my web.php
'modules' => [
'v1' => [
'basePath' => '@app/api/v1',
'class' => 'api\v1\Module'
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'pluralize' => true,
'controller' => [
'v1/country',
'v1/user'
],
],
],
],
Module.php
<?php
namespace api\v1;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'api\v1\controllers';
public function init()
{
parent::init();
}
}
Contry.php model
<?php
namespace api\v1\models;
use \yii\db\ActiveRecord;
class Country extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'country';
}
/**
* @inheritdoc
*/
public static function primaryKey()
{
return ['code'];
}
/**
* Define rules for validation
*/
public function rules()
{
return [
[['code', 'name', 'population'], 'required']
];
}
}
CountryController.php
<?php
namespace api\v1\controllers;
use yii\rest\ActiveController;
{
public $modelClass = 'app\api\v1\models\Country';
}
Going to: http://mysite.com/countries
Not found (404)
Going to: http://mysite.com/country
<response>
<item>
<code>AU</code>
<name>Australia</name>
<population>18886000</population>
</item>
<item>
<code>…
I don’t know where I’m doing wrong…