Dynamic CSS files

I had always wished CSS files weren’t so static so you could do different things at runtime. It turns out you can do it, but exercise common sense. The exact plan you take depends on how often the CSS “variables” change value. If it’s not too often you might want to “precompile” the style files into static and just use them the old style way.

Here is how you can use PHP to do ‘on-the-fly’ CSS files.

  1. Instead of including a static css file include a file with the php suffix as below:
    <link rel='stylesheet' type='text/css' href='css/style.php' />
    
  2. Make sure your style.php file returns the appropriate headers for a text/css mime type as below:
        header("Content-type: text/css; charset: UTF-8");
    
  3. Now set up variables in your style.php very much like you would for a view template:
     $mainUrl = "http://dorkage.net";
     $mainHeaderColor = "#FE0EDE";
    
  4. Refer to your variables using echo
    #header {
       background: url("<?php echo $mainUrl; ?>/images/header-bg.png") no-repeat;
    }
    a {
      color: <?php echo $mainHeaderColor; ?>;
    }
    

CSS Tricks.com reported a different way to do this: This match rule in htaccess matches any file with style in it’s name and gets parsed as PHP thusly:

<FilesMatch "^.*?style.*?$">
SetHandler php5-script
</FilesMatch>

They speculate that you wouldn’t be able to take advantage of the automatic cacheing that is normally provided for style files. However, you could precompile your style.php by running it through CLI php each time you update the “variables” thusly:

php style.php > style.css

and just include the resulting css file the normal way

Listen to this post Listen to this post

Zend Framework and Doctrine

doctrine_iconWell it’s looking like Doctrine is the heavy weight data mapping solution of the lot. Zend Framework was often criticized for having no serious Model methods. Models was just sort of where you put your nuts and bolts database code. Some folks like the structure of the Active Record model that you see in Rails some other PHP frameworks. Sure it makes it dead easy when your tables map pretty straightforwardly onto your objects but makes it harder to have complex objects involving many tables. Zend was working on their own Zend_Entity package to remedy this, but they have abandoned it in favor of integrating Doctrine. The Zend Roadmap for the future calls for tight integration of Doctrine with the framework, so there will probably be some additional automatic linkage, with the view to the framework user’s code being smaller. But both ZF 2.0 and Doctrine 2.? are for PHP5.3, which is some time down the pike for ordinary folks. On the ZF Wiki there is a proposal to integrate current versions, at least to some extent. The symfony camp are hollering that Doctrine automatically “just works” in symfony, and that’s great. But for now you do have to do a little work to integrate it with ZF.
Continue Reading…

Listen to this post Listen to this post

How to integrate a jQuery plugin into Yii Framework

I have been studying up on Yii framework as a potential alternative to Zend. It has its pluses and minuses. Yii framework comes with jQuery included at the core. It was ridiculously easy to download a jQuery plugin, drop it in as a black box, follow the instructions for the front end, and it just works. I used the star-rating plugin. If you have a rating for a piece of content represented as a number such as 3.642/4 on a scale of 0-4, it is much more Web 2.0 friendly if you represent that graphically. Star-rating uses pimped up radio buttons to represent this number as five fractional stars. It also does the front end of dynamic interactive ratings, and as soon as I get my ajax back-end working on that I’ll post that too. Since the actual code being typed in is illegible in the video, I have included it in this article.

Continue Reading…

Listen to this post Listen to this post

Berio Free Video Screen Capture for Leopard

Camtasia is awesome, but pricey. For the likes of me, who doesn’t do video screen capture for a living, the price just isn’t justified. Leopard comes with an app to do capture, but it requires a hookup to a MacOSX server. Out of luck again. Enter Berio. Simple Straightforward, and does the job. You can talk while you’re mousing as well. Downside: Five minute limit.

Free download from http://www.juniortan.com

Listen to this post Listen to this post

FirePHP: Firebug for PHP

firephp_largeFirebug is da bomb for debugging your web front end. Instead of just being able to look at the page source as it was delivered from the server, it lets you see the modified page after Javascript has run it through the ringer, it breaks things down heirarchically to help you focus, and it even lets you edit a page locally.

Now you can do the same to serverside PHP with FirePHP, a Firefox/Firebug add on. Note: You have to have Firebug to use FirePHP. I’m guessing FirePHP piggybacks onto some of its presentation structure.
Continue Reading…

Listen to this post Listen to this post

Captcha a la XKCD

This XKCD comes at just the right time for me. I’m struggling with an issue with the Captcha in Yii Framework. In case you didn’t know, the captcha is that slightly distorted codeword that you type into a computer program to tell it you’re a human being. Bots supposedly can’t read them…. Of course I don’t really see a problem with chatting with a bot if it’s a good enough one to provide you joy and/or other types of entertainment. XKCD fans tend to be abstract types anyway.

OK, I pledge to post my problem with the Yii captcha and why I have to override it and my solution, because it potentially affects Leopard users.

Listen to this post Listen to this post

Alternatives to Zend Framework

I am currently feeling very conflicted about Zend and everything associated with it. I heard a statement the other night by a guy who was talking about CakePHP that hit the nail on the head. Paraphrasing what he said,

“There is nothing wrong with Zend Framework, but you just get this feeling with Zend that there will come the day when it’s going to become painful for you if you don’t shell out big bucks to them.”

Shades of Microsoft…. BLEAH! I am afraid the day has come. I was a big proponent of Zend. It’s difficult to eat a bit of crow and do a 180 on something you’ve taken a stand on, but when I examine things rationally, I’ve been increasingly disillusioned with Zend. There are several sticking points, elaborated below:
Continue Reading…

Listen to this post Listen to this post

Dojo toolkit wrapper

I’ve been finding lately that my simplest blog posts grow the longest tails. So here is one for all you dojo toolkit users or wannabe’s. I started seeing the following in dojo scripts that I hadn’t seen before, and couldn’t find any specific comments about it.

;(function(d,$){ /* your code here */})(dojo, dojo.query)

The leading semicolon is a fudge in case you’re using the build tools and glomming multiple files and the one ahead of yours forgot its trailing semicolon. An extra semicolon won’t hurt anything.
In my world (linux conf files), a leading semicolon often is a comment marker, so even though I know that is not the case in ECMAscript (AKA Javascript), it still caused me to do a double take.

The purpose of the anonymous function is to parameterize dojo and dojo.query so that you can use d to refer to dojo, and the JQuery/prototype style $ as shorthand for queries. That’s all there is to it. It also serves to point up a less used way to both define and call a function all in one bang.

Listen to this post Listen to this post

Bar Camp Melbourne 12-13 Sept 2009

barcampmelbourne-2009-logo-v2-500x127 Australians have bar camps too. This one won’t be free, but it will be cheap depending on what corporate sponsorship they get. It’s a big sleepover, so you’ll need a sleeping bag. Click the banner to go to their site to sign up: Signups open 12 August. It will be at Urban Camp right in Royal park (right smack on my #55 tram, what could be better?) Here’s a mini map: click on it to get a bigger one.
urban_camp
Hope to see some of my new Melbourne friends there!

Listen to this post Listen to this post

Instant Access to 5 million row CSV for MySQL

mysqlI was investigating the CSV storage engine for mysql, having never used it. I found out, much to my relief, that it’s a relatively new thing — went standard with 5.1, but certainly not in the kits of luddites like me who have to stay four or five versions back because we can’t afford downtime caused by unexpected glitches with new releases.

The CSV engine is as I expected: It allows MySQL to directly access CSV files. There are probably boocoo performance issues and I don’t know how easy it is to later convert a table with its engine declared as CSV to something more standard such as MyISAM.

I think the big plus of the CSV engine is that you can quickly and easily leverage your existing CSV files from excel, as long as you are not looking for excellence in relational, normalized database design. Having been out in the trenches, I would guesstimate that 98 percent of MySQL users would not know normalized form if it bit them in the butt and they still manage to get work done. The CSV engine would probably give you a speed advantage for quick and dirty projects but I don’t think it is a great idea for a long standing, constantly updated database.
Continue Reading…

Listen to this post Listen to this post