Configure stylesheet with PHP

Asked

Viewed 1,708 times

1

I’m setting up an administrative system and one of the administrator’s options is to control various page color settings. However I’m having difficulty finding the best way to put these settings on the site.

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

NOTE: I am using Codeigniter in this project.

  • Bro sorry to write on your question yesterday managed to resolve me a situation could give me just more tip put in the comment follow the link https://answall.com/questions/227945/peg-dados-xml-com-php?rq=1

  • I missed the link : https://answall.com/questions/273834/pega-dados-json-imprimir-php/273841#273841

  • I answered there. Take a look if that’s right

  • Perfect bro thanks a ok la to you

  • Help choose the best answer, vlw.

2 answers

1

Yeah, man, make a file, nome_que_quiser.php then you pull what you have to pull on it +/- like this:

//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"/>

Already if you want to use .css, think I’d 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 Voce would have to call the constants that Voce wants to use file by file. For example the arquivo.php would have to do that.

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

/project
    /css
        arquivo.php
    constants.php

Ending

You can take a look at this website.

I’ve used this before (.php I talk), but I stopped this site because I gave a forgotten.

  • Thank you for the reply

  • Quiet, I hope you help others too.

0

The most indicated in your case would be using SASS, so you could assign the colors as the user prefer.

You can also simply save these customizations in a database and then when loading the page your PHP will tell the CSS which color should give that element. thus:

//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>

hope I’ve helped.

  • I wanted to center this so I wouldn’t keep repeating code on every page.

  • So put this customization in a single file and use the "require_once" to call for the other pages friend, easy!

Browser other questions tagged

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