Streamlining CSS with PHP goes against good practice?

Asked

Viewed 96 times

2

Streamlining CSS with PHP goes against good practices?

I need to change the header background image of a page according to her article. I thought about writing the CSS inside a PHP file for this, but I don’t know if it’s considered a good practice... or worse, a bad hearing.

NOTE: I also thought about doing this using AJAX so as soon as the page loads, it access the database, take the name of the image and change in CSS.

  • 1

    I use this device on some of my websites, depending on the version (Portuguese, Italian, Spanish or English) the background image is the country of the chosen version. There is no other way because it is a single php page that builds the html in the chosen version. But you can make your css file and leave the style in php only from the background image part.

1 answer

1


Yes, it is a bad practice if you work with Design Patterns and MVC architectures. However, if you program structured, I see no problem, but there are better ways to create a dynamic CSS, with javascript and Ajax. You can do Ajax and use Jquery events, for example:

$.ajax({
   url: "test.html",
   context: document.body
}).success(function() {
   $( this ).css( "background-color", "#00000" );
});

I hope I helped! Any questions, we are there!

  • Yes, as I said in the post I thought about using AJAX for this, but I figured there might be a way to do this in the document by the same back-end. But thank you so much for the clarification. I will use AJAX even since I am working with MVC. Thanks !

  • Yes, as you use MVC, front-end and back-end do not mix, so Javacript is the best way to streamline your CSS. Hug!

Browser other questions tagged

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