Welcome Guest, Not a member yet? Register   Sign In
Send a variable from a controller, to view, to css-file
#1

[eluser]Unknown[/eluser]
Hello everybody!

I've been using CodeIgniter for quite some time now..I think about six months. I really like its straightforwardness and extendability.
Today I was using it on a new project of mine. This project is a simpel CMS-system, with a front and a backend. In the backend I have a page where users can select a main color for the website (I used http://code.google.com/p/mcolorpicker/ for this). When submitted, the color is stored in a database.

Next stop, the front. I have a controller that gets this color from the model and stores it in a variable. This var gets send to the view and I loop through it to use this color on several items on a page - like hyperlink, menu background, logo, etc.

For now this approach works fine, but I was wondering if it was possible to send the variable, from the controller to the view, which sends it to a css-file.

Thanks in advance!
#2

[eluser]iloveci[/eluser]
I believe there is some major failure of logic going on here. I'm unsure why your trying to send variables to your css file.

I believe what you want is a base CSS file, that handles all the styling of the elements on your page, Then additional color-specific css files. So then when you need to change from say red to blue, use php to load blue.css instead of red.css.

Does this make sense?
#3

[eluser]Unknown[/eluser]
Well, it does make more or less sense, but what you are suggesting, actually limits my options of available color selection. Either that, or I should generate a whole lot of css-files.
In a previous project, which was pre-CodeIgniter, I generated a css-file, which I renamed to a .php-file. Then I added a constant like so:

Code:
<?php
define('COLOR','FF00FF');
define('COLOR2','000000');

?>

//some css styling
a {
text-decoration: underline;
color: #<?=COLOR?>;
}

However, adding constants to a css file, generates on error. That is why I was wondering if it possible to send a variable to a css file.

Thanks again for your help.
#4

[eluser]eggzy[/eluser]
Take a look at http://net.tutsplus.com/tutorials/php/su...-the-hood/




Theme © iAndrew 2016 - Forum software by © MyBB