0

I want to generate a CSS file based on the users choices.

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',
 ),
);

2
  • "MySQL seems to be clumsy at storing that kind of data." what kind of data ? Can you explain your situation/desired solution a bit more? Commented Aug 26, 2010 at 17:43
  • Im assuming that is php (I'm not a php guy). Isn't php dynamic? Couldn't you just save that and eval() it to get your array, similar to how it is done with json/javascript? Commented Aug 26, 2010 at 17:44

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I can't believe I missed that one! It is ridiculously simple!
1

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

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.