V
V
Vladislav2014-09-06 21:23:41
PHP
Vladislav, 2014-09-06 21:23:41

How to hook API to MVC for Ajax requests?

How is the API attached to MVC?

Those. API acts as a standard controller, model with logic and output (instead of HTML code, output json)?

Requests like: site.ru/api/login_user/name/pupkin/pass/12345

I want to use this API for authorization, registration, etc...
i.e. handle all forms with Ajax))

Am I on the right track or not?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evansive, 2014-09-06
@Evansive

Yes, but the logic for passing requests to the API can be moved to a separate library. Call library methods from the controller.

X
xmoonlight, 2014-09-06
@xmoonlight

All true, but not quite.
Do a normal POST/GET handler on the controller - that's the starting point.
And then - fork based on the URL:
without api/ajax: HTML-form-builder (preparing the code for displaying the form in the view module),
with api/ajax: JSON

A
Alexander Kubintsev, 2014-09-07
@akubintsev

Under the API, it makes sense to make a separate entry point, that is, there is no need to interfere with the logic of the website and api.
Also I wouldn't pass all parameters via GET. Let's say let there be a request like /api.php?object=LoginController&action=auth, and send login and password already in POST.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question