The only option that seems to be woring well is the enablePrettyUrl, all the other options break my WebApp. I only have some default models and controllers. Nothing really OUTOFTHEBOX yet.
But is kind of frustrating not knowing why the example does not work.
Anyone is using the RESTful Web Service wihing Yii2.0 ?
Would be great to know how you did it! Thanks for everything !
Default restful controllers rely on ActiveRecord, but in basic app template User model extends Object, not ActiveRecord, so you need either to modify this, or use other model.
I’m using the Basic Template, i created a simple model ‘Category’ within the Gii module, so my model is extending the ActiveRecord Class.
Then i created the CategoriesController extending the 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';
}
I added a RewriteBase url value to my htaccess file because my webserver’s documentRoot and my webapp are in separate folders:
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
My application just works fine with prettyUrls & without showing ScriptName (always when setting enableStrictParsing to false or adding the related controllers to Roules)
But when acceding to localhost/~salem/alpha2/web/categories i’m having the following error:
Not Found (#404)
Unable to resolve the request "categories/index".
So the application is detecting the CategoriesController Class witch extends the ActiveController Class in witch the indexAction is defined within the ActiveController::actions() and my ActiveRecord model is assigned to the $modelClass property but steal, my app cant find the index action ??