Category: Development

  • Login system with CakePHP in under 10 minutes

    ** If you’ve found this article through a Google search, visit my CakePHP 2.x Login System for an updated version of this article. **

    In today’s article, I am going to discuss how simple it is to setup a login system with CakePHP.  As the title says, it should be less than 10 minutes.  In theory if you copy and paste the code below, it should be fully functional in less than 5.

    Ready, set, let’s bake. (more…)

  • Optimize your CSS and JS with CakePHP in minutes

    One of my first articles discussed YSlow.  An excellent Mozilla add-on to help you understand why your web page may be loading slowly.

    In that article, I describe the importance of gzip, minify, and grouping your Javascript and CSS code into one file each.

    Just recently I was surfing CakePHP’s bakery and found a nice add-on to simplify the process and make it super easy. (more…)

  • Importance of using the CakePHP Helpers

    Uggghh, I hate to even be writing about this!  I have been spending the past two days cleaning up a project that has been running for over one year.  It was our first ever CakePHP project at our company and we were too lazy to be consistent about using $html->link() when creating our links.

    Just recently the client has requested a change for their Facebook application.  We simply need to add a “requirelogin” HTML attribute to every link. (more…)

  • Re-map key/value array data in PHP

    I was recently tasked with a situation where I needed to populate about 10 different “Settings” for every user in the current database.

    This example is specifically for CakePHP, however, it could easily be used elsewhere.  My goal was the following, I had an array that was key value paired as follows:

    array(
     [0] => array(
      ‘User’ => array(
       ‘id’ => 1)
      ),
     [1] => array(
      ‘User’ => array(
       ‘id’ => 2)
      ),
     [2] => array(
      ‘User’ => array(
       ‘id’ => 3)
      ),
     [3] => array(
      ‘User’ => array(
       ‘id’ => 4)
      ),
    )

    The result I needed was as follows:

    array(
     [0] => array(
      ‘UserSetting’ => array(
       ‘user_id’ => 1)
      ),
     [1] => array(
      ‘UserSetting’ => array(
       ‘user_id’ => 2)
      ),
     [2] => array(
      ‘UserSetting’ => array(
       ‘user_id’ => 3)
      ),
     [3] => array(
      ‘UserSetting’ => array(
       ‘user_id’ => 4)
      ),
    )

    With a few simple lines of code, I was able to quickly and easily achieve this, let me show you how. (more…)

  • When to use element() and when to requestAction()

    Several times a week it seems, someone at my office is asking, “Jamie, should I use $this->element() or $this->requestAction()?”

    Every time they ask, I ask them back, “What do you need to do?”

    There are a few simple ways to determine if using an element is better or a request action is better. (more…)