tomar un controller existente y crear otro igual con distinto nombre.
Por ejemplo ItemsController.php -> Ws_itemsController.php
2)
hacer las sgts modificaciones
class Ws_itemsController extends ActiveController
{
/**
* @inheritdoc
*/
// adjust the model class to match your model
public $modelClass = 'app\models\Items';
public function behaviors()
{
return
\yii\helpers\ArrayHelper::merge(parent::behaviors(), [
'corsFilter' => [
'class' => \yii\filters\Cors::className(),
],
],
[
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
]
]);
}
3)
en web.php
...
'urlManager' => [
....
'rules' => array(
......
['class' => 'yii\rest\UrlRule', 'controller' => ['ws_items']],
),
],
...
4)
en web.php
Opcionalmente, para que pueda aceptar como imput json
....
'components' => [
'request' => [
.....
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
5)
GET /
ws_items: list all books page by page; HEAD /
ws_items: show the overview information of book listing; POST /
ws_items: create a new book; GET /
ws_items/123: return the details of the book 123; HEAD /
ws_items/123: show the overview information of book 123; PATCH /
ws_items/123 and PUT /books/123: update the book 123; DELETE /
ws_items/123: delete the book 123; OPTIONS /
ws_items: show the supported verbs regarding endpoint /books; OPTIONS /
ws_items/123: show the supported verbs regarding endpoint /books/123.
No hay comentarios:
Publicar un comentario