Archive for the ‘CakePHP’ Category

22 May 08 _ 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.

Hat tip: Greg Knaddison at the Drupal forums.

04 Apr 08 _ 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:


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

And now the sort direction in the generated URL will flip between ‘asc’ and ‘desc’ depending on the current listing.

Also, if you want to show the user which way we’re currently sorting, you can including the current sort direction as a class on the link:


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

This will add the classes ‘asc’ or ‘desc’ to the link, and you can do some easy CSS styling to show directionality:


a.asc {
     padding-right:20px;
     background-image: url(../img/up-arrow.gif) top right no-repeat;
}

a.desc {
     padding-right:20px;
     background-image: url(../img/down-arrow.gif) top right no-repeat;
}


There’s lots more on pagination, make sure to check out the two Bakery articles: Basic Pagination Overview, and Advanced Pagination, both by Rob Conner.

31 Mar 08 _ 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.

26 Feb 08 _ 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).

Regardless, if you want Cake to display a “404 Not Found” error message if the ID isn’t found or returns no data, do something like the following:


function view($id=null)
{
    if ($id) {
           $data = $this->Model->findById($id);
           if (!$data) {
                 $this->cakeError('error404',array(array('url'=>'/')));
           } else {
                 $this->set('data',$data);
           }

    } else {
           return false;
    }

}

That will throw up Cake’s generic 404 error page and stop further script execution for ya. If you want to have a custom 404 page, add a file named “error404.ctp” to your /app/views/error/ directory.

19 Dec 07 _ 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.


class GroupTest extends TestSuite { }

Ah! The SimpleTest program itself was declaring the GroupClass for doing group tests. So just renaming my model to “GroupTestModel” or the like fixed the problem.

  • guitar modification parts
  • butcher paper roll dispenser
  • makers of dog kennels
  • credit card debt relief program
  • billet grills
  • studio rta the bug computer desk
  • shark cordless cyclonic hand vacuum
  • toastmaster parts toaster
  • men's suits shirts barney
  • saucony shoes outlet stores
  • 1 2 decorative square post caps
  • fruit of the loom union suits
  • maine snowmobile insurance requirements
  • boyne mountain grand lodge and spa
  • triple pet natural toothpaste
  • used kids dirt bikes for sale
  • 30 inch slide in electric range
  • create pdf word embed fonts
  • wholesale jelly jars
  • water as fuel denny klein
  • couch replacement pillows
  • coleman bayside elite replacement parts
  • sponge bob crabby patty candy
  • wholesale winter gloves hats
  • best at home treatment for blackheads
  • tub refinishing pgh pa
  • tile shower seat vintage
  • caught wearing high heels split skirt
  • kawasaki kx85 parts and exploded view
  • india and business dress
  • kid's camp crafts
  • cuff bracelets wholesale
  • golf gps systems reviews
  • wholesale patio pool furniture
  • crystal on the plaza
  • global travel shoes
  • spectrum products tanning bed
  • 84 wide wooden window blinds
  • consigning my lilly pulitzer clothes
  • no smoking rooms in boston hotels
  • aubrey organics skin cleanser
  • home decor liquidators furniture and flooring
  • hair regrowth products reviews
  • black bean corn citrus vinegar
  • jt paintball gear
  • how to create finger nail designs
  • popup tent cleaning
  • knife sound editing
  • hippie chick costumes
  • miniature surveillance cameras detection
  • hd high def video edit
  • recycle styrofoam cups
  • bamboo patio door blinds
  • money order promise rings
  • resurfacing bathtubs
  • mens star earrings
  • spray face foundation
  • remote home thermostats
  • phoenix skin rejuvenation
  • shower enclosures walls
  • kawasaki 440 aircraft engine parts
  • women's clothing sleep shirts
  • material requirements planning mrp systems
  • cryoserver back email compliance archiving message
  • home flea infestation
  • cuisinart 9-speed hand mixer brushed chrome
  • wholesale military surgical caps
  • nike drawstring backpack lavender
  • acutane colon problems
  • mercedes 320 wagon tires
  • ucla womens basketball camps
  • vida international fruta
  • kids camp crafts
  • compliance corporate email
  • good feet store onalaska wi
  • coach purse party
  • women's shoulder handbags
  • diy exterior patio blinds
  • pivot tub shower enclosures
  • dog harness and collar
  • shoi racing helmets
  • free shawl knit patterns
  • thyme essential oil price
  • tubeless bicycle wheels road
  • black edition magazine man swimsuit
  • 5 star car wax
  • italian charm bracelets wholesale
  • sleep t shirts
  • audio cards upside down
  • dell 5100cn colour network laser printer
  • fj cruiser trailer hitch receivers
  • sell structured settlement payment
  • organizational monitor stands
  • prom decorations and costumes
  • cats on behavior medication
  • golf palm computer gps system
  • budget wedding planning checklist
  • movie theater popcorn maker canada
  • water pump 3-inch suction hose
  • invest in stocks cheap
  • nike max air inline skates
  • star wars galactic heroes bedding comforter
  • airsoft outfitters gear
  • cheap new chevy trucks
  • discounted airfares cheapest airfares erfurt
  • floral furniture throws
  • schutt baseball equipment
  • acrobat distiller settings for news print
  • 2.4 to 3.8 s10 truck conversion
  • westgate villia resorts
  • fuzzy bunny slippers adult
  • shock doctor mouth pieces
  • midwest family vacations
  • red kap highland uniform shirts
  • play euchre free online
  • rockport shoes rosemont
  • elo entuitive touchscreen drivers
  • decorative garden pond fountains
  • kids online cake decorating games
  • america west airlines dividend miles program
  • in kind giving from popcorn company
  • camera ccd industrial
  • outdoor furniture pool harrows
  • raymond waites spring garland
  • lil boosie new mixtapes
  • household and cleaning forum
  • video piggy 1.3.0 crack