Set up style sheet with PHP

1

I am setting up an administrative system and one of the administrator options is to control various page color settings. But I'm having a hard time figuring out the best way to put these settings on the site.

I thought about creating a style sheet with only the settings that the admin will modify and put the php code that pulls this information from the database, but how to do it? Can I simply put a PHP extension on that sheet that everything will work?

  

NOTE: I am using Codeigniter in this project.

    
asked by anonymous 03.02.2018 / 21:12

2 answers

1

//arquivo.php

<?php header("Content-Type: text/css; charset=UTF-8"); ?> //note <<

.container {
    width: <?php echo $user_container_width; ?>
}


//index.html
...html
<link rel="stylesheet" href="arquivo.php"/>

If you want to use nome_que_quiser.php , guess you would have to do something like

//.htaccess
AddType application/x-httpd-php .css
AddHandler php5-script .css

Editing

Another thing, the problem is that this guy (css / php) does not run along with your application, in case you would have to call the constants that you want to use file by file. For example, .css would have to do this.

//arquivo.php
require("../constants.php");

/project
    /css
        arquivo.php
    constants.php

Final

You can take a look at this site .

I've used this before (.php I speak), but I visited this site because I forgot it.

    
03.02.2018 / 21:39
0

The most appropriate in your case would be to use SASS, so you could assign colors as the user prefers.

You can also easily save these customizations to a database and then by loading the page your PHP will tell the CSS which color should give that element. like this:

//arquivo.php

<body>
  <style>
    #elementoPersonalizado1{
      background-color: <?php echo $cor_armazenada_na_tabela;?>;
    }
  </style>
  <div id="elementoPersonalizado1">
    <p>O fundo dessa div tera a cor que esta armazenada no banco de dados</p>
  </div>
</body>

I hope I have helped.

    
03.02.2018 / 22:14