yii - besides default endpoint create custom endpoints -
i following tutorial
http://learncooltech.com/yii2-angular-how-to-create-single-page-application-in-minutes/
i got tutorial work , can see /books: list books page page;
however, want create endpoints , in controller added method test 404. here controller
namespace app\controllers; use yii\rest\activecontroller; class bookcontroller extends activecontroller { public $modelclass = 'app\models\book'; public function behaviors() { return \yii\helpers\arrayhelper::merge(parent::behaviors(), [ 'corsfilter' => [ 'class' => \yii\filters\cors::classname(), ], ]); } public function actiontest(){ return json_encode(array("name"=>"john doe")); } }
i have urlrule
'urlmanager' => [ 'enableprettyurl' => true, 'enablestrictparsing' => true, 'showscriptname' => false, 'rules' => [ ['class' => 'yii\rest\urlrule', 'controller' => ['book']], ], ],
and doing
http://localhost/events/test
to endpoint
and this
<head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="csrf-param" content="_csrf"> <meta name="csrf-token" content="cwdhtlznwe8unn5jedqvhwzxjdcuiykkadujagm/ei4dxn4moawncg=="> <title>not found (#404)</title> <link href="/assets/a7503887/css/bootstrap.css" rel="stylesheet"> <link href="/css/site.css" rel="stylesheet"> </head> <body>
got working changing rule this
'rules' => [ ['class' => 'yii\rest\urlrule', 'controller' => ['book'], 'extrapatterns' => [ 'get test' => 'test', ], ],