Feed items

How to flip text upside-down on Twitter

Here’s a little trick I just saw on Twitter that will let you tweet upside down. All you do is go to this website and enter the text that you want to flip and reverse:
http://www.revfad.com/flip.html

¡ǝldɯıs ʇɐɥʇ s,ʇı
It’s that simple!

Follow us on Twitter: @AWPNY

How to get CakePHP to work in a subdirectory

I recently had trouble getting CakePHP running properly in a subdirectory on the Mosso cloud. The main site URL is http://thinkandthrive.com, and the Cake app lives in a folder off the site root called “tw”. So I was able to connect to http://thinkandthrive.com/tw/, but not to http://thinkandthrive.com/tw (without the trailing slash).
The fix to get Cake working in the subdirectory was to add a single line to the .htaccess file in the Cake root directory ( the “/tw” folder in my case). The .htaccess file should look something like this:

RewriteEngine on
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L]

Add this line after “RewriteEngine on”:
RewriteRule /YOURCAKESUBDIR$ /YOURCAKESUBDIR/ [L]

Obviously, replace “YOURCAKESUBDIR” with the subdirectory your Cake app in running in. So my .htaccess file now looks like this:

MySQL Transactions With CakePHP 1.2

Whew, been a while since I’ve posted something useful.
Hopefully, everyone is aware of MySQL transactions and how useful they can be.  They come in especially handy when you want to save multiple related entries into different tables in your app.  Cake actually already uses this in a behind the scenes way with the Model::saveAll() function, which does some of this for you (you can read more about saving your data with saveAll() here).
But you can easily use Transactions for anything you want to do.
Note: for this to work at all you have to make sure whatever table you’re using transactions with are of the type InnoDB, and not the standard MyISAM type.

CakePHP 1.2 RC2 + Security Component

I’ve been wrangling with the Cake’s Security Component for the past day, not having the best time with it. If you’ve been trying to use it, you may have noticed that there seems to be near-total lack of documentation on it. Not cool.
So I was trying to use it to make some simple HTTP Authentication requests for a WebTree site of ours. It turns out that whenever the Security Component is initialized in a controller, it requires that all POST-ed data in that controller be validated through the Security Component. For this to work correctly, and not spit you out into a blank page “black hole,” you have to use the Form Helper for every form that needs to be submitted, making sure to use $form->end().
It looks like the Form Helper builds a Hash number based on the name of the fields included in the form and the Security Salt that you set in the config/core.php.

Sluggable Behavior + RC2

Ahh, yes. The shared pain/annoyance of upgrading Cake from RC1 to RC2 and finding that the SQL operator syntax has changed.  Sure it’s more sequre, sure it’s not as elegant looking, and sure there seems to be zero backward compatibility, but yeah, it happens.  It’s still a pre-release.  We deal.
So for those that currently use iano Iglesias’ super-helpful Sluggable Behavior, make sure to change line 121 from:
$conditions = array($Model->alias . '.' . $this->__settings[$Model->alias]['slug'] =>' LIKE ' . $slug . '%');

to:


$conditions = array($Model->alias . '.' . $this->__settings[$Model->alias]['slug'] . ' LIKE '=> $slug . '%');

The current version, 1.1.36, does not include this fix for Cake RC2. Without this, you’ll start getting duplicate slug values, lacking any numerical appending action.

Mosso Hosting and CakePHP

We here at the shop have playing around with a pretty cool new hosting solution, called Mosso. It’s a cloud-computing technology with some pretty good ideas, albeit buggy at times. A review of this whole system is grounds for a whole ‘nother (longer) post, but in the mean time, I wanted to share a piece of knowledge with getting CakePHP to run correctly.
It’s pretty simple, actually. For each .htaccess file that Cake has (in the root, /app/, and /app/webroot/) you need to add this line right after the RewriteEngine is initialized:


RewriteBase /

After that everything works totally fine. If you don’t do this for each file, you’ll get 500 Internal Server errors popping up all over the place.

CakePHP 1.2 Pagination Note

I just noticed that in CakePHP 1.2 beta (6311), if you’re using the paginator helper, and attempting to sort data with the sort() function, AND you’re passing URL information, you need to specify the model explicitly in order to have the function take care of flipping the asc/desc sort direction.
Maybe this will make it more clear:
If I was just doing this:


< ?php
echo $paginator->sort('Name','name',array('url'=>Router::getParam('pass')));
?>

The generated sort link would always have the sort direction set to ‘asc’. Is this a bug? I’m not sure, probably. (Notice how I feed the Router’s pass params into the URL to preserve the current passed arguments to the controller function). To make this work, just specify the model explicitly:

A PHP Developer’s Keyboard


Too many times writing <?php echo(’stuff’); ?>? Or just a dirty pinky finger? Why would my little finger be so much grittier than the others? Why is it red? Pounding out that damn PHP code too hard, probably.

Throw Down 404 Errors in Cake

Say you’re doing some simple display logic for a controller view:


function view($id=null)
{
if ($id) {
$this->set($data,$this->Model->findById($id));
} else {
return false;
}

}

In a situation like this, you always want to handle the (inevitable) situation when someone requests an invalid ID number, at which point no data would be returned in the $data variable.
Luckily, there’s a handy little function called cakeError, which lets you call a variety of Cake errors. Most of the time, you’ll want a 404 error, but it also lets you call any Cake-standard errors (you can see the full list here).

Beware Testing Group Models in Cakephp

If you haven’t read the Bakery article on Testing Models in Cakephp, by Mariano Iglesias, you should go and read it now.
Having read that, there is something to watch out for. I have a authorization system that uses a model called Group which hasMany users. Ok. After making a series of tests in the vein of Mariano’s article, I came across this error when trying to run the test:

Fatal error: Cannot redeclare class GroupTest in /xxxx/app/tests/cases/models/group.test.php on line 6

Line six of group.text.php was pretty basic, just declaring the GroupTest class model to use in the test:

class GroupTest extends Group {
var $name = 'GroupTest';
var $useDbConfig = 'test_suite';
}

After poking around a bit, I found this, on line 608 of test_case.php in the /vendors/simpletest/ directory.