Answer the question
In order to leave comments, you need to log in
How to change BjyAuthorize behavior to work with REST API (HTTP methods, RestfulController)?
You need to make it work with RestfulController's actions (get, getList) or with HTTP methods coming in Request (GET, POST, PUT) instead of AbstractActionController's actions.
At the same time, it is desirable to retain the ability to control and ordinary actions, since they can be created in RestfulController'e. It would probably be more convenient to get the names of the RestfulController'a methods (get, getList), and not HTTP Request'a, so as not to mess up the config add. http_method/controller_method parameter.
How can I get the name of the RestfulController's called action (get, getList, etc.)?
What services and providers need to be changed?
Answer the question
In order to leave comments, you need to log in
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',
],
],
];
class LoginController extends AbstractRestfulController {
public function create($data) {
// POST данные пришедшие по REST
return new JsonModel(['status' => 'error', 'message' => 'Логин и/или пароль указан не верно.']);
}
public function getList() {
// GET данные без id
return new JsonModel(['item1', 'item2', 'item3']);
}
public function loginAction() {
// обычный Action
return new ViewModel();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question