yii code inside css

hi, i want users to have a feature where users can select color, font ,font size, font color etc. is it possible to write php code inside css files like




<?php

$width=10px;

?>







.colorpicker-saturation {

width:100px;

height:100px;

background-image:url(../images/colorpicker/saturation.png);

cursor:crosshair;

float:left;

}



is it possibile?

Absolutely. All you have to do is to serve the CSS as a result of a controller action. With the appropriate Content-Type header, of course.

Yep, just how phtamas said. I implemented this recently for a cms project.

In my controller


public function actionLayoutCss()

{

    $css = $this->renderPartial('index', array(

        'css' => get my css data from db and send it to view

    ), true, false);

    $this->renderCss($css);

}

I extend my CController (this is not necessary, you could just do this from the controller) with that renderCss method which is simply


protected function renderCSS($data)

{

    header('Content-type: text/css; charset: UTF-8');

    echo $data;

    Yii::app()->end();

}

And my view is a php file, so I can use data from the database, like a chosen background color.


/**

 * My Sites Custom Layout CSS

 * <?php echo date('Y-m-d H:i:s', time()) . "\r\n"; ?>

 */


body { background-color: <?php fetch it from db (probably passed from the controller); ?>; }

Something like that.

thanks guys