Published on Jun 11, 2013 by Jamie Munro
Published on Jun 3, 2013 by Jamie Munro
I’ve long professed how I dislike convoluted controllers. CakePHP’s find method almost immediately causes this when used inside a controller. More importantly, the code inside the find method is extremely unreadable. This is almost more important than a large controller function!
This is where the repository pattern comes in. At its most basic example (which some will consider overkill – you know who you are), I still think the repository pattern is clearer.
Here is an example using the regular find approach:
$user = $this->User->find('first', array('conditions' => array('id' => $id)));
Compared to a repository example:
$user = $this->UserRepository->GetById($id);
The code is almost identically; however, in the second example, it’s clear that if I were to “read” the code I am retrieving a user by id opposed to I’m finding the first user with the conditions of id being equal to the variable $id.
So if you are sold, let’s continue with a full suite example…
Published on Jan 30, 2013 by Jamie Munro
One of the things that immediately caught my mind was this great big bolded sentence:
Model::find('first')will now return an empty array when no records are found. Make sure you update your tests!
Immediately after reading this I thought major code changes were going to be required; however, luckily my fear was unfounded. Let me provide an example...
Published on Jan 7, 2013 by Jamie Munro
The first article I wrote is an excellent extension of the various CakePHP articles I've written about in the past. It discusses a variety of ways to improve the speed of CakePHP applications. The latest article (that was just released a few days ago) discusses creating your very own OAuth server. Since OAuth2 is still in a draft state, the article is for creating an OAuth1 server.
In case you are not a regular of this site, here is a quick preview of the articles.
Published on Sep 21, 2012 by Jamie Munro
I know I certainly was and became determined to understand what the heck these were doing. It quickly became apparent that these were just two of the many built-in extension functions that are part of the CakePHP framework!
Published on Sep 10, 2012 by Jamie Munro
Published on Jun 25, 2012 by Jamie Munro