database driven CSS? |
[eluser]kwhitaker[/eluser]
Good afternoon all, I'm writing an app that needs to let the end user input custom CSS for an item, and then have it called via a query. Now, I know I could embed the styles into the HTML, but that goes against my anal-retentive-standards-based-to-a-fault methodology Is there a way to link to something like styles.php?css=some-number in the header, and then the styles.php could pull data from the DB based on that number? Thanks!
[eluser]Pascal Kriete[/eluser]
Not quite as you put it, but sure it's possible: Code: class Assets extends Controller { So now linking to http://www.example.com/assets/css/something will try to load 'something' from the db.
[eluser]Bramme[/eluser]
You can do this with a .htaccess file. You could implement the php queries in your .css file and then tell apache (through the .htaccess file) that it needs to handle the css file as php (and thus processes the queries). I don't know the code for it, so you'll have to google that. Of you could make a simple .htaccess redirect: make a css.php file in your css folder that queries the db and builds the css file and then redirect using .htaccess. Adding an id to the url is easy with this: Code: RewriteEngine on
[eluser]xwero[/eluser]
Why not use javascript and a cookie. The javascript is for switching the style and the cookie is to store the user setting for return visits.
[eluser]Bramme[/eluser]
That would work if you only need a few css files... What if every user can define it's own stylesheet colors and you have about 1000 users
[eluser]xwero[/eluser]
The user is able to do his own styling so it are the themes you provide as a developer and your own theme. If others can be chosen i think it will happen in a gallery. I would create a physical css file per user instead of generating it from the database. |
Welcome Guest, Not a member yet? Register Sign In |