开发者

Generating a CSS file from file or database (PHP)

I want to generate a CSS file based on the users choi开发者_开发技巧ces.

I am considering which way would be best. On example is to use arrays and save them in a XML file or use a key/value store like Mongo DB.

In that way the array can be pulled from the XML or key/value database, modified and saved. After that a CSS file would be generated based on that data. That is to ensure that the CSS file always would be created correctly.

MySQL seems to be clumsy at storing that arrays unless I use EAV. that is why I mention key/value database like mongo DB.

The reason for all this are that I just want to make a nice user interface where user witout CSS knowledge can generate their own theme.

I just want to present the user with a form where they can fill out color, width etc.

What do you think would be good?

Example of array:

$css = array(
 'body' => array(
  'font-family' => 'arial',
  'font-size'  => '12px',
 ),
 'wrapper' => array(
  'margin'=> '20px auto 20px auto',
  'width' => '900px',
 ),
 'content' => array(
  'background-color' => '#c3c3c3',
  'width'    => '900px',
 ),
);


You can use the serialize function to put the data into a format that can be stored in a MySQL database field. On retrieval you would then use the unserialize function to restore the variable.


The best solution would probably be to use a dynamic CSS file. Save the values as an array in your database and pass them to a PHP file masquerading as a CSS file to set the dynamic values. Check this out: Embedding PHP In CSS


Why don't you save the data as a CSS file, and then parse, load, and save back to that file when the user wants to make changes? Then you don't need to worry about generating the file when it's requested.


I think Mongodb would be perfect. You could keep your default CSS and then only overwrite the fields that the user has entered. I also think a relational db like mysql would just get in your way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜