<?php
namespace app\controllers;
use yii\rest\ActiveController;
use app\models\Object;
class ObjectController extends ActiveController {
public $modelClass = 'app\models\Object';
public function actionView($id)
{
return Object::findOne($id);
}
}
Please give me a hint for the url manager, so that I can put a (id) parameter in my class method.
Now I’m “quite sure” that I need the “extraPattern” inside my rules, to specify a setting for parameters. But I’m still lost at this point. I’ve played a bit around and my conclusion is:
if I specify “enableStrictParsing”, I’m getting the “Page not found.”-message instead of “Unable to resolve the request “object/view/1”.”-message. Also if I call domain/object/view without “enableStrictParsing”, I get the xml-message:
With “enableStrictParsing” I’m getting just “page not found”.
again, you shouldn’t need to specify anything in your controller to get the view action working: it should work out of the box via the following url http://yourdomain.com/objects/<ID> : this will trigger the view action and passing the ID automatically.
Just to recap, in config/web.php you just need to have:
<?php
namespace app\controllers;
use yii\rest\ActiveController;
use app\models\Object;
class ObjectController extends ActiveController
{
public $modelClass = 'app\models\Object';
}
and from there you should be able to access /objects to trigger the index action and /objects/<ID> to trigger the view action as I said at the beginning.
Thanks for your answer. The problem was, that I’ve always wrote DOMAIN/object/ID instead of DOMAIN/objects/ID. I’ve missed the plural (objectS). Thanks for your help.
is set. Otherwise I can only call specific objects. With "false" I can get all objects. In the wiki is written, that by enabled strict parsing, for every url call a method must be set.