1

Yii 2.0(ベータ) で統合された RESTful Web サービスを使用している人はいますか?

公式ドキュメントの手順は単純に見えますが、私にはうまくいきませんでした: 私は基本的なテンプレートを使用しており、gii モジュールを使用して拡張する単純な「カテゴリ」モデルをActiveRecord作成しました。CategoriesControllerActiveController

# 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割り当てられます。$modelClassActiveControllerindexview

私の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& showScriptNameto false は問題なく動作していますが、localhost/~salem/alpha2/web/categoriesにアクセスしようとすると、次のエラーが発生します:

Not Found (#404)
Unable to resolve the request "categories/index".

誰が私が間違っているのかについて何か考えがありますか??

ありがとう

4

1 に答える 1

0

答えは、上にリンクされた同じドキュメントにありました。コントローラーの名前は UserController かもしれません..." enableStrictParsing を無効にし、ルールを削除してから、コントローラーの名前を CategoryController に変更しました。できます!

于 2015-03-12T14:58:40.520 に答える