How to change the behavior BjyAuthorize to work with REST APIs (HTTP methods, RestfulController)?

Need to get him is a action games AbstractActionController'to work with ekshenom a RestfulController' (get, getList) or incoming HTTP methods in Request (GET, POST, PUT).

It is desirable to maintain the possibility of control and action, since you can create them in RestfulController'e. Probably would be easier to get the names of methods RestfulController'a (get, getList), not HTTP Request'a that would not foul extra config parameter http_method/controller_method.

How do I get the name of the called action RestfulController'a (get, getList, etc.)?
What services and providers need to replace?
September 19th 19 at 00:19
1 answer
September 19th 19 at 00:21
config/module.config.php
return [
 'router' => [
 'routers' => [
 'api-login' => [ // REST
 'type' => 'Literal',
 'options' => [
 'route' => '/api/login',
 'defaults' => [
 'controller' => 'YourModule\Controller\Login'
],
],
],
 'login' => [
 'type' => 'Literal',
 'options' => [
 'route' => '/login',
 'defaults' => [
 'controller' => 'YourModule\Controller\Login'
 'action' => 'login',
],
],
],
],
],
 'view_manager' => [
 'strategies' => [
'ViewJsonStrategy',
],
],
 'controllers' => [
 'invokables' => [
 'YourModule\Controller\Login' => 'YourModule\Controller\LoginController',
],
],
];

src/YourModule/Controller/LoginController.php
class LoginController extends AbstractRestfulController {
 public function create($data) {
 // POST the data came at REST
 return new JsonModel(['status' => 'error', 'message' => 'Username and/or password is not correct.']);
}

 public function getList() {
 // GET the data without the id
 return new JsonModel(['item1', 'item2', 'item3']);
}

 public function loginAction() {
 // normal Action
 return new ViewModel();
}
}


you should pay attention to the fact that:
  • The controller is inherited from the AbstractRestfulController
  • In the config specified strategy ViewJsonStrategy
Routing, and restful controllers I have written and work. I need to configure the authorization module, which is called BjyAuthorize and works by default only with the AbstractActionController. I need to configure this module to work with the RestfulController https://github.com/bjyoungblood/BjyAuthorize - Shanny_Steuber commented on September 19th 19 at 00:24

Find more questions by tags RESTful APIZend Framework