PJ Hile

Don’t worry, I’m from the Internet.

PJ Hile header image 1

Ignoring CakePHP’s tmp/ directory with Subversion

July 30th, 2008 · 2 Comments

I’ve noticed on many occasions that I’ll start a project with a Subversion repo and immediately add/commit all the files included with Cake’s nightly build including the tmp/ directory.  If you’ve ever done this, you’ll know it’s kind of a pain always having those cache/log files showing up when you commit.  So, for my benefit, I’m posting these few lines of code in order for me to refer to later.

From the app/ directory:

svn export tmp tmpBAK
svn rm --force tmp
svn ci -m 'Removing directory "tmp".'
mv tmpBAK tmp
svn propset svn:ignore 'tmp' .
svn ci -m 'Ignoring "tmp" directory.'

→ 2 CommentsTags: CakePHP · PHP · Subversion

Changing the CakePHP Auth component password hash

May 29th, 2008 · 5 Comments

In moving some legecy sites over to CakePHP, I’ve come across some situations where I need to the Auth component to ‘hash’ the password differently. For example, just a straight md5() of the password.

To accomplish this, you need to empty your Security.salt variable in /app/config/core.php (Not positive what all this will affect):

Configure::write('Security.salt', '');

and change the hash method of the Security class (I did this in app_controller.php):

function beforeFilter(){
   Security::setHash('md5');
}

→ 5 CommentsTags: CakePHP

Twitter client for Ubuntu

May 22nd, 2008 · 2 Comments

TwhirlTwhirl is an Adobe Air based Twitter client, and one of my favorites for use on my Dell Latitude D630 running Ubuntu Hardy Heron.  For instructions on how to install Air, click here. Then, download/install Twhirl from here.  Total install time is 5-10 minutes.

→ 2 CommentsTags: Twitter · Ubuntu

Bluetooth on Dell D630 - Ubuntu 8.04 Hardy Heron

May 6th, 2008 · 2 Comments

Dell UbuntuIt took a little bit of work for me to get my Dell bluetooth mouse and keyboard working with my new work laptop (Dell D630), but in the end it was pretty easy.

First, make sure gnome-bluetooth and bluez-gnome are installed in Synaptic.  Then, in a terminal type “sudo hidd –search” and click the little bluetooth button on the underside of the mouse/keyboard.

→ 2 CommentsTags: Dell · Ubuntu

Putting a Google Map on your site with PHP: Part 1

March 24th, 2008 · 1 Comment

Google MapThe first step in getting a Google map on your site is to get the latitude and longitude coordinates of all the points you want to show. I get my coordinates using geocoding in the Google Maps API. In order to use the Google Maps API, you must sign up for a free key here.

Once you have your key, it’s as simple as:

// Desired address
$address = "http://maps.google.com/maps/geo?q="
.urlencode($data['address'])
.”,+”.urlencode($data['city'])
.”,+”.urlencode($data['state'])
.”,+”.urlencode($data['zip'])
.”&output=xml&key=”.$_SESSION['GOOGLE_KEY'];


// Retrieve the URL contents
$page = file_get_contents($address);


// Parse the returned XML file
$xml = new SimpleXMLElement($page);


// Parse the coordinate string
list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates);

We now have $longitude/$latitude, which we will need for rendering our map.

Notes:

  • I used to get the coordinates inside of my map generation, but sometimes the map would finish rendering before all the coordinates had been downloaded, so I suggest you get all your coordinates before you render your map.
  • My example makes use of SimpleXMLElement() which I believe is a PHP5 and above only function. If you use PHP4 or below, you will have to parse the xml some other way.
  • You don’t need the altitude for map generation, but they give it to us anyway.

→ 1 CommentTags: Google · PHP

Javascript strings over multiple lines from PHP

March 13th, 2008 · No Comments

I had a problem where I was defining javascript variables from php variables, and the php variables had multiple lines.

So, a function like this:
function SomeFunction() {
var variable = "<?php echo $variable; ?>";
}

was creating this:
function SomeFunction() {
var variable = "The first row.
The second row.
The third row
";
}

The fix was to replace all the ‘\n’ with ‘\\n’, so the literal string ‘\n’ is output instead of an actual line break.

Like so:
var variable = "<?php echo str_replace('\n', '\\n', $variable); ?>

→ No CommentsTags: Javascript · PHP

Send more data with CakePHP’s observeField()

March 10th, 2008 · 3 Comments

CakePHPI just ran into a situation today that required me to have access to more than one form field when doing an ajax request within my CakePHP application. Basically, when someone is typing an address, I want to check Google’s Geocode API for a latitude and longitude coordinate.

The important part is the ‘with’ option:
'with'=>'Form.serializeElements($("CommunityForm").getElements())'

My example:
echo $ajax->observeField('CommunityAddress', array('with'=>'Form.serializeElements( $("CommunityForm").getElements() )','url'=>'geocode','update'=>'geocode'"));

  • The data being passed can be accessed in $this->params
  • This solution requires the Prototype javascript library.

→ 3 CommentsTags: CakePHP

Command line script to recursively delete .svn folders from a directory

January 17th, 2008 · 1 Comment

find ./ -name ".svn" | xargs rm -Rf

source: http://www.rickhurst.co.uk/category/linux/

→ 1 CommentTags: Uncategorized

MySQL to MSSQL with PHPMyAdmin

November 19th, 2007 · No Comments

Tux / LAMPA client has forced me to migrate a MySQL database to MSSQL. Using PHPMyAdmin here is a list of things I had to do in order to get the data over:

  1. ‘SQL compatibility mode’ to ‘MSSQL’
  2. Uncheck ‘Add AUTO_INCREMENT value’, ‘Enclose table and field names with backquotes’, ‘Complete inserts’, ‘Extended inserts’
  3. Remove all occurrances of ‘unsigned’
  4. Replace ‘id int(10)’ with ‘id int(10) IDENTITY (1,1) PRIMARY KEY CLUSTERED
  5. Replace all ticks (`) with quotes (”)
  6. Remove all PRIMARY KEY lines
  7. Remove all KEY lines
  8. Remove all ENUM data types
  9. Remove lengths from all int types (int,smallint,tinyint)
  10. Replace date with datetime
  11. Replace tinytext with text
  12. Remove all ‘\r\n’

→ No CommentsTags: Uncategorized

Scriptaculous blind effect with CakePHP

October 11th, 2007 · No Comments

Scriptaculous
The Scriptaculous effects are easy to implement in CakePHP. I looked around for a simple example and didn’t find one, so here you go!

<?php echo $html->link('Dinner Menu','#',array('onclick'=>'Effect.toggle("dinnerMenu", "blind", {duration: 0.2}); return false;')); ?>

<dl id=”dinnerMenu” style=”display:none;”>
<?php foreach ($event['Meal'] as $meal): ?>
<dt><?php echo $meal['name']; ?></dt>
<dd><?php echo $meal['description']?></dd>
<?php endforeach; ?>
</dl>

Make sure to download the appropriate libraries to your /app/webroot/js/ directory and reference them in your layout file.

<?php
if(isset($javascript)):
echo $javascript->link('prototype.js');
echo $javascript->link('scriptaculous.js?load=effects');
endif;
?>

→ No CommentsTags: Uncategorized