D
D
DoubleDecker2020-11-11 08:27:42
PHP
DoubleDecker, 2020-11-11 08:27:42

How to correctly transfer data from the backend to the front?

It is undesirable to mix business logic in php and the front, but how should it be right then? For example, I need to get some value from the database and transfer it to the front. What is the best way to do this?
Here I have an api that returns any information from the database. How to embed this information in html? Is it appropriate to access the api through JS and use it to embed information in html? In general, I would like to know how to correctly and appropriately connect the back and front.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1BX.host Hosted by, 2020-11-11
@1BX_host

hmmm. well, as if on the back, you make a call to your api, pull the data and format it right there in the same file into readable html
Using JS, pulling data and inserting it into the current page is only appropriate if you need dynamics caused by user activity (that is, there is already screw ajax)

L
Lone Ice, 2020-11-11
@daemonhk

Template engines give you the ability to insert values ​​directly into the template, for example {$variable}. You can use any one you wish.
You only need JS for whistle-blowing, and for AJAX, animation, reactivity, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question