Answer the question
In order to leave comments, you need to log in
How to make PHP and React JS friends?
I just started learning Node + React JS, Redux. Full kettle.
Dear gurus, poke your finger in solving this problem.
There is a small real estate site on smarty php. All requests are made through the MYSQL database.
Tell me (if there is such a solution, but it’s better to show an example or links to specific documentation with examples) how to make it right that in Reacte it was possible to receive and send requests from mysql?
example:
connected react
<script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/babel.js"></script>
<!-- мой файл react js -->
<script type="text/babel" src="{$estate_folder}/template/frontend/{$current_theme_name}/js/main.js"></script>
private function getAgents()
{
$ret = array();
$DBC = DBC::getInstance();
$query = 'SELECT * FROM ' . DB_PREFIX . '_user WHERE group_id<>4 AND login<>\'_unregistered\' ORDER BY RAND() LIMIT 3';
$stmt = $DBC->query($query);
if ($stmt) {
while ($ar = $DBC->fetch($stmt)) {
$ret[] = $ar;
}
}
$js_obj = json_encode($res);
$this->template->assign('agentslist_items', $ret);
}
{literal}
<script>
var obj=$js_obj;
alert(obj);
</script>
{/literal}
Answer the question
In order to leave comments, you need to log in
Don't combine React and PHP in the same application. Create two different projects.
And reduce all communication between them to REST, for example.
Use your build systems in these different projects (some kind of crutch for both will not lead to anything good, they tried in Laravel). Place them on different subdomains then in production.
They don't do that. The meaning of the react is lost.
The whole point of js frameworks is to separate the frontend into a separate application that works with the backend via api. And what will be there on the back - laravel, pure php, node or python - it does not matter at all.
React is a state-oriented product. We work from the state. Php is a pure mvc classic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question