2016-05-11 9 views
1

Ich habe versucht, von diesem http://budiirawan.com/setup-restful-api-yii2/ RESTful API-Modul zu installieren, und ich bin immer FehlerYii2 erholsamen api Objekt nicht Fehler gefunden

Objekt wurde nicht gefunden!

Ich versuchte Einstellung mod_rewrite und auch AllowOverride All Konfiguration.

Ich habe auch angeschlossen, um die Datenbank zu korrigieren, und diese Datenbank hat country Tabelle darin.

Ich habe auch .htaccess Datei und hier ist meine api/config/main.php Datei

<?php 
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'), 
require(__DIR__ . '/../../common/config/params-local.php'), 
require(__DIR__ . '/params.php'), 
require(__DIR__ . '/params-local.php') 
); 

return [ 
'id' => 'app-api', 
'basePath' => dirname(__DIR__), 
'bootstrap' => ['log'], 
'modules' => [ 
    'v1' => [ 
     'basePath' => '@app/modules/v1', 
     'class' => 'api\modules\v1\Module' 
    ] 
], 
'components' => [ 
    'user' => [ 
     'identityClass' => 'common\models\User', 
     'enableAutoLogin' => false, 
    ], 
    'log' => [ 
     'traceLevel' => YII_DEBUG ? 3 : 0, 
     'targets' => [ 
      [ 
       'class' => 'yii\log\FileTarget', 
       'levels' => ['error', 'warning'], 
      ], 
     ], 
    ], 
    'urlManager' => [ 
     'enablePrettyUrl' => true, 
     'enableStrictParsing' => true, 
     'showScriptName' => false, 
     'rules' => [ 
      [ 
       'class' => 'yii\rest\UrlRule', 
       'controller' => 'v1/country', 
       'tokens' => [ 
        '{id}' => '<id:\\w+>' 
       ] 
      ] 
     ], 
    ] 
], 
'params' => $params, 
];  

Hier ist das Modell Country

<?php 

namespace api\modules\v1\models; 

use yii\db\ActiveRecord; 
/** 
* Country Model 
* 
* @author Budi Irawan <[email protected]> 
*/ 
class Country extends ActiveRecord 
{ 
/** 
* @inheritdoc 
*/ 
public static function tableName() 
{ 
    return 'country'; 
} 

/** 
* We use the primary function because we don't use integer auto increment as a primary key. 
* @inheritdoc 
*/ 
public static function primaryKey() 
{ 
    return ['code']; 
} 

/** 
* To let Yii know what fields exist on the table. 
* Define rules for validation 
*/ 
public function rules() 
{ 
    return [ 
     [['code', 'name', 'population'], 'required'] 
    ]; 
} 
} 

ich immer noch die gleichen Fehler, während es durch http://localhost/yii2-api/api/v1/countries erreichbar.

Antwort

1

Laut Tutorial Sie haben url zu verwenden:

http://localhost/yii2-api/api/web/v1/countries 

Statt

http://localhost/yii2-api/api/v1/countries 
Verwandte Themen