D
D
dmitriy2015-02-20 11:27:47
PHP
dmitriy, 2015-02-20 11:27:47

How correct is it to use php wrappers for js code?

Many js plugins have php example libraries for quick connection and use in my projects, I myself use this approach, and it seems convenient to me. To what extent is it considered correct, isn't it a g ... code?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
O
OnYourLips, 2015-02-20
@OnYourLips

The plugin requires functionality on the server side. This is fine.
Sometimes, when using a ready-made JS code, I do not use its back-end part and write it myself if I need to do another action, and not the one that the author meant.
This happens very often: for example, they use the wrong database or other tools.
So take the server side as an example.

D
dmitriy, 2015-02-20
@dmitriylanets

here we mean the generation of js code using php
for example

$jgrid->addColumns([..]);
$jgrid->setName('mygrid');
echo $jgrid->init();//на выходе js код плагина

A
Alexey Yakhnenko, 2015-02-20
@ayahnenko

And in a different way, you can’t transfer data from the backend to the JS level.
Well, so that they were immediately, without ajaxes.
So this is the norm.

B
Boris Benkovsky, 2015-02-20
@benbor

1. Of course, real-time JS code generation in PHP, shit code. Then there will be a desire to write like this

<script>
   var jsVar = <?= $phpVar?>;
</script>

And when there will be a lot of such shit .... there will be sadness.
2. Such JS will not be cached by the browser, which is always very bad.
3. It would be better, of course, to file a separate JS code that retrieves data through data attributes ( <div data-some-value="12341"></div>) , and php sets it there.
All these either, this is the norm if you are aware of what you are doing, AND you need a quick start, or the project is generally very small. Then maybe not Feng Shui

A
asdz, 2015-02-20
@asdz

Do not piss, if this solves the problem and there will be no problems with support in the future, then feel free to sculpt!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question