How do I integrate React into a MVC (PHP) structure?

Asked

Viewed 317 times

-1

I am learning PHP and I came up with a question: With React, we have the CLI, which is a structure already ready for you, with all the necessary files. In MVC we built a structure separating the view, controller and model into different folders.

The question is: In the MVC structure, I must download the CLI package from React in order to use it, or just copy the CDN to the views and use it normally?

1 answer

1

the ideal would be to turn your php code into a REST API. This API would return only the data in JSON without view, which will be used in React.

You would have your controller based on JSON returns, example:

public function index() {
  $dados = []; # qualquer dado

  http_response_code(200);
  return json_encode($dados);
}

In React, you can use the library Xios, to make the requests in the - php API.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.