Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
ymas4717yIMO, PHP is a pretty good templating language in and of itself. I guess you could use something like twig or nunjucks (for the more JavaScript inclined) but if your pages are rendered server side then plain PHP is good enough.
-
echo '<script>
var para = document.createElement("p");
var node = document.createTextNode("This is new.");
para.appendChild(node);
var element = document.getElementById("div1");
element.appendChild(para);
</script>';
easy 😕 -
ch0s3n1827yGenerally it's a good idea to separate the pieces that do different things. This way it's easier to decipher what's what and the code becomes more manageable. Especially if you're not the only one working on the code.
You still may need to inject some variables into your html tags which is fine. But if you have php functions and logic that can be written elsewhere then you should do so. -
curlyDev4727yMVC...
Make them in php but dont put the logic in there.
Dont show html and do mysql query in same file. -
@curlyDev MVC doesn't apply much in the server side it is pretty linear, it is just separation of concerns
-
What they usually mean, is that in your views, you shouldn't have more than if's and for loops.
No further logic or calculations or database interaction or whatever. -
Conrad7537yMy solution is to only have php: The html parts are all in heredocs and get assembled into one variable that is echoed at the end. Pure php, just what you wanted :p
-
Build a JSON api using php
Use html and js to consume it.
In short you don't mix html with php because php generates json which is basically arrays and js reads them. You use ajax to send and receive data from php.
That's how I began...
Yesterday I was told to not mix HTML with PHP.
My reaction:
Why not? And how else should I do?
Don't get a answer to this.
rant