Category: PHP

  • Using CakePHP with the jQuery Sortable Plugin

    It’s time to permanently remove all “manual” sorting from the Internet. You know the one I mean where it has the up and down arrows – or even worse, the text box that accepts a numerical order input. By implementing the jQuery template Sortable Plugin, you will be able to provide a simple, but effective drag-and-drop ordering solution for just about any type of data! I’ve also got a lot of other jQuery tutorial examples for beginners.

    In a recent article, I described the required HTML and Javascript code need to implement the jQuery Sortable Plugin on a gallery of images. If you haven’t already done so, please begin by reading this article because this one will gloss over those features and focus on how to implement this with CakePHP.
    (more…)

  • Cannot find module (SNMPv2-TC)

    When I run PHP via the command line (aka php cli), I often would be spammed with the following error messages:
    Cannot find module (SNMPv2-TC)
    Cannot find module (SNMPv2-SMI)

    Messages like this would repeat for 30 or 40 lines. These errors would not stop my command from executing; however, it was extremely noisy when trying to see the output.

    (more…)

  • 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…)

  • What Do You Care Most About When Reviewing Someone Else’s Code?

    I wrote an article a few months ago called Compelling Interview Questions where buried deep in the middle under several open-ended technical questions I asked the question “What Do You Care Most About When Reviewing Someone Else’s Code?”

    The funny part about this when you read a few lines below I follow it up with I’m not looking for anything in particular; just some generic catch-phrases that most people throw out there.  E.g. properly indented code, no large comment blocks, documentation to explain a complex block of code, etc…

    Ask me today what I expect from this question and my answer is totally different!  Today being as I write this article – ask me in the present and let’s see if my answer changes…

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