Yii 2.0(ベータ) で統合された RESTful Web サービスを使用している人はいますか?
公式ドキュメントの手順は単純に見えますが、私にはうまくいきませんでした: 私は基本的なテンプレートを使用しており、gii モジュールを使用して拡張する単純な「カテゴリ」モデルをActiveRecord
作成しました。CategoriesController
ActiveController
# Content of the file app\controllers\CategoriesController.php
<?php
namespace app\controllers;
use yii\rest\ActiveController;
class CategoriesController extends ActiveController
{
public $modelClass = 'app\models\Category';
}
これで、モデルは、または:( ActiveController::actions()を参照)などの定義済みの CRUD アクションと関連付けるためにクラスで必要となるプロパティにCategory
割り当てられます。$modelClass
ActiveController
index
view
私のUrlManager
設定は次のようになります:
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'categories'],
],
],
私の Web サーバーの documentRoot と webapp は別のフォルダーにあるため、WEB フォルダーの下の htaccess ファイルは次のようになります。
RewriteEngine on
RewriteBase /~salem/alpha2/web
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
PrettyUrls
& showScriptName
to false は問題なく動作していますが、localhost/~salem/alpha2/web/categoriesにアクセスしようとすると、次のエラーが発生します:
Not Found (#404)
Unable to resolve the request "categories/index".
誰が私が間違っているのかについて何か考えがありますか??
ありがとう