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.

Download Full Movie Online Abilify Wyvern download movie Little black book download movie In a dark place download movie Munich download movie Broken bridges download movie Shiloh 2: shiloh season download movie Scooby doo meets batman download movie ringtones for go phones uploading free ringtones make your own ringtones samsung awesome ringtones where to get free ringtones for att Meet the Spartans download movie Enter the Dragon download movie Congo download movie Airheads download movie Canvas download movie Cashback download movie Heavenly Creatures download movie Finishing the Game: The Search for a New Bruce Lee download movie The Level download movie Straight-Jacket download movie Deathline download movie Kung Pow: Enter the Fist download movie Showtime download movie Lean on Me download movie The Story of Anyburg U.S.A. download movie Tinker Bell download movie Under Siege download movie Killing Ariel download movie Street Trash download movie Smart People download movie Crimson Tide download movie Donald's Tire Trouble download movie The Donor Conspiracy download movie The Bank Job download movie The Final Conflict download movie The Lookout download movie Footlight Parade download movie Outside Providence download movie New York Stories download movie In the Heat of the Night download movie Taxi Driver download movie Carry on at Your Convenience download movie My Boss's Daughter download movie The Black Gestapo download movie 8MM 2 download movie Texas Rangers download movie Meet the Spartans download movie Enter the Dragon download movie Congo download movie Airheads download movie Canvas download movie Cashback download movie Heavenly Creatures download movie Finishing the Game: The Search for a New Bruce Lee download movie The Level download movie