Archive for the ‘Code’ Category

Set media=print Using The CakePHP CSS HtmlHelper

Posted on July 18th, 2008 in CakePHP, Web Development, Code | 2 Comments »

It seemed so simple, yet it took forever to figure this one out. I’ve been using CakePHP for several projects lately, and I’m really enjoying using it. But much of the documentation is lacking. Luckily there are plenty of blogs detailing the progress of this framework and what can be done with it. But I searched in vain for quite a while on how to create a link to a css file and designate it for “print” only.

Here’s how to create a link to a stylesheet and set the media type to “print”:

$html->css(array('filename'), 'stylesheet', array('media' => 'print'));

That will output the following code:

<link href="/css/filename.css" rel="stylesheet" type="text/css" media="print" />

Hope that helps the next person trying to figure this one out.

Change Your Domain Name and Keep Your Incoming Links With .htaccess And mod_rewrite

Posted on September 12th, 2007 in Web Development, Apache, Code | No Comments »

When moving our site from ablogapart.org to michaelkrol.com, this handy little bit helped move our entire website with four lines of code:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)ablogapart.org [NC]
RewriteRule ^(.*)$ http://michaelkrol.com/$1 [R=301,L]

This reference was extremely helpful.

This RewriteRule lives in the .htaccess file at ablogapart.org and tells any request coming in to that domain to swap ablogapart.org out and replace it with michaelkrol.com. This includes ANYTHING after the trailing slash, like a direct link to a previous post. So http://ablogapart.org/this/direct/link gets sent properly to http://michaelkrol.com/this/direct/link

The important part is the [R=301] which sends a 301 (Permanent) Redirect header. That tells search engines that the page has moved permanently.

Just imagine what you’d have to go through setting up individual forwarding links…

PHP mail() And Gmail - A Warning on Headers

Posted on December 7th, 2005 in Web Development, Linux, Fixit, Code | 9 Comments »

Today, out of nowhere, we started receiving reports that HTML email the gdiapers.com site was sending were showing up as just that: HTML code and not much else. Running a few tests confirmed these reports… but only in my gmail account. We went back and checked the reports and sure enough - they were all coming from gmail users.

After some tinkering and futzing around we realized that the Windows line breaks that we had after the headers (\r\n) were the problem. Here’s an example:

This will show up as two line breaks in gmail and trash your HTML formatting:
$headers = "MIME-Version: 1.0\r\n";

This, however, will fix the problem and show up in gmail just fine:
$headers = "MIME-Version: 1.0\n";

I’m sure if you were sending mail from a Windows server this may not be the case, but for those on a Unix box, just stick with \n. Google will thank you by displaying your HTML email the way it was meant to be displayed - without raw code!

Close
E-mail It