Category: CakePHP

  • Setting Up CakePHP with IIS

    I’ve found myself doing this several times over the past little while as I had to switch computers.  Each time I would struggle with a few of the steps, so I thought I would document them this time and share for future me (or you if you like).

    (more…)

  • Implementing the Repository Pattern with CakePHP

    I must admit, my recent articles are becoming a bit obsessed around the repository pattern.  What can I say, I like it, it’s useful, and it’s not restrictive based on a language or a framework.

    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:

    [code]
    $user = $this->User->find('first', array('conditions' => array('id' => $id)));
    [/code]

    Compared to a repository example:

    [code]
    $user = $this->UserRepository->GetById($id);
    [/code]

    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…

    (more…)

  • Changes to Model:find(‘first’) in CakePHP 2.3

    A new stable release of CakePHP has just been released a few days ago, version 2.3.  With this many great new changes have come out of it.  You can read the full change log here:
    http://bakery.cakephp.org/articles/lorenzo/2013/01/28/cakephp_2_3_0_is_out

    One of the things that immediately caught my mind was this great big bolded sentence:

    IMPORTANT: Model::find('first') will now return an empty JavaScript 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…

    (more…)

  • Recent Guest Posts on PHPMaster.com

    I’ve had the pleasure of being a guest writer at a fantastic site called phpmaster.com.  This site is a subsidiary site to one of the most popular technology blogging sites sitepoint.com.

    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. (more…)

  • CakePHP Global Constants and Functions

    If you ever find yourself perusing some of the default code that comes with CakePHP, you might find yourself somewhat curious and confused when you see such functions as <?php e(‘Hello World’);?> or <?pho echo h(‘<a href=””>Hello World</a>’);?>.

    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!

    (more…)