Welcome Guest, Not a member yet? Register   Sign In
PHP variable in css
#1

[eluser]stingray9[/eluser]
Hey,

has anyone of you having experience using php variables in css?
I was thinking to make a project were the customer could chose his own site colors (will be saved in an SQL database).

What is the easiest way to do it in CI?
Any suggestions?

Thanks!
#2

[eluser]macron[/eluser]
Hi

Load it as a view. The whole css file could be a php file. So use something like this:
Code:
<link rel="stylesheet" href="/theme.php" type="text/css" media="screen" charset="utf-8" />
where "/theme.php" is a view as in
Code:
<link rel="stylesheet" href="<?php $this->load->view('css/theme')?>" type="text/css" media="screen" charset="utf-8" />


Hope this helps

/Kaj
#3

[eluser]stingray9[/eluser]
Thanks, I guess this will do it.
I will test it soon, but sounds logical.. Wink
#4

[eluser]Unknown[/eluser]
Vai amar aita somporke kono knowledge nai????????????????????????????????


Halar po nije paros na???????????????
#5

[eluser]Basketcasesoftware[/eluser]
Quote:Vai amar aita somporke kono knowledge nai????????????????????????????????


Halar po nije paros na???????????????

What on earth is that? :question: :bug: :question: What language? I was expecting a reply on the results of this css experiment. (I could use it if it works).
#6

[eluser]stingray9[/eluser]
Hey guys,

i still got a problem, i hope anyone knows a solution how to solve it.
I need to get results from my database in my css.

What i have now is my css in php:
<LINK HREF="css/style.php" REL="stylesheet" TYPE="text/css">

The style.php has his header configured as text/css. It works fine, but now i need to replace some variables to variables I get from my database.

How can i get/use results form my database in my style.php?

Edit: As solution i write the css where i need database results just in my view, not in my css. But that doesn't look very well..
#7

[eluser]Basketcasesoftware[/eluser]
How are you executing style in the first place? Is "style" a controller?
#8

[eluser]stingray9[/eluser]
No, it's a view.
#9

[eluser]Basketcasesoftware[/eluser]
Views aren't actually executed outside of a controller. Controller->View->Output. Does your host even execute php code in css loads? If not you will have to use a View to generate a file output. e.g.:
Code:
class Css_generator extends CI_Controller
{
function __construct()
{
    parent::__construct();

        $this->load->helper('file');
}

function index()
{
    $data=$this->get_my_style_data();
    $css=$this->load->view('style',$data,TRUE);

        if ( ! write_file('css/style.css', $css))
        {
                echo 'Unable to write the file';
        }
        else
        {
                echo 'File written!';
        }
}
}

This is just a rough example of course.
#10

[eluser]InsiteFX[/eluser]
The best way of doing this is to use js with a style switcher.

I have written one here somewheres I will see if I can find it,
it stores a cookie on the users system so that it knows witch
style sheet to load.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB