The Wonderful World of PHP Frameworks - CakePHP and Laravel

November 13, 2013

If you’ve read any of my previous posts you know that I’ve just started developing seriously in PHP a bit over a year ago. It was great fun watching my skills progress but now that I’ve gotten some perspective, I feel like the code I’ve written in that time is truly ugly. In my previous post on where to work I mentioned that at my current job I wrote a simple CMS back end for our writers to create their own HTML pages. Well, this process began long before I familiarized myself with MVC or any of the popular frameworks out there. I had heard of Zend but I just thought it was something with a really cool name that I would never have to give a hoot about. Turns out I was wrong.

As my CMS system began to grow and require additional features and maintenance (including moving our phone record system in) I noticed something – tracking back through all of these classes, methods, and functions was a drag, man. Seriously, when this thing was a config file, functions file, and throw in pages with some javascript it was great – but lately it has turned into a beast. My company had brought in a veteran developer to help create a very advanced intranet system for our company a few months back. I had helped him migrate the source files from his computer to our local server and chatted him up about his work and tools etc. – all stuff that I was hungry to know. He mentioned that he had decided to step out of his comfort zone on our project and build it in a new framework he hadn’t used – CakePHP. Naturally after things had been migrated I poured over that source that had just been moved and realized I didn’t have the foggiest idea of what was going on. I mean, sure classes and methods, but how the heck was this arranged? Why was I seeing stuff in the app folder that wasn’t in others? Why

![Confused computer meme]( "Confused at the computer")Wat?
was one thing extending another that was extending another? My fertile and confused brain needed answers so I started to familiarize myself with MVC and the popular frameworks out there.

MVC sounded fantastic and all but I found myself getting lost in the lingo. I’m a hands on kind of learner so telling me all about abstractions, business logic, separation of concerns, and dependency injection left me a bit frazzled. Fast forward to October ’13. My company recently purchased a really, really, really expensive domain name that we have big time plans for. We’ve all agreed that the site built on said uber TLD needs to be second to none (actually, in our ‘widget’ business it’s not hard – lots of companies have garbage websites). With that said, I was posed this question – so, should we build it in wordpress? A few years ago my naive self would have giggled and said OF COURSE! My newly educated self said – would Amazon or Target or, like, *anyone with lots-o-pages with advanced needs *build it in wordpress? No, of course not. So off I go to the internet super highway to bone up on my MVC and PHP frameworks again. It turns out there are way more than even the major players that I had heard of. At any rate, I recalled what my advanced developer friend and compiled for us in CakePHP and decided to give it a go.


So, I started down what I had hoped would be a long path with  CakePHP. I had done some research and plenty of people had mentioned ‘the learning curve’ but I figured ‘I’ve lived and breathed PHP for the past year, I can do this’. Installation and setting everything up on my local WAMP server went just peachy. So far, so good. Like any logical human being I decided to start out in the documentation from the source itself at I read up on the basics but, again, I am a hands on learner so tutorial time. CakePHP’s documentation includes a tutorial on setting up a very basic blog with cake. This sounded right up my alley. A few steps in I started to realize I had a problem. Everything seemed to be running just fine but the documentation – well – the documentation kind of sucked. If you find yourself here as a Cake veteran PLEASE do not get up in arms – I’m sure cake is fantastic when you know what you are doing but as a beginner stepping into an MVC framework for the first time it was a head scratcher. It seemed like it was geared toward the experienced framework developer that understood the nuances and just need the general ‘this goes here, invoke it this way, return and parse like this’.  But, for a beginner, I needed a lot more hand holding. Plus, as the tutorial went on I realized that sending large amounts of data to methods in arrays was just totally miserable. I’m as big a fan as any one of braces and brackets  – but when you’re on your fifth nested array it’s like looking at that horrible 3d art from the 90’s.

![3d art]( you see it?! It’s a cat flying a spaceship while playing a fiddle!
Being the go-getter that I am I was undeterred. Have you guys heard of this thing called Ruby on Rails? HAHA jk jk jk – I knew about that even before I knew what it actually was. I toyed with that a bit and really enjoyed picking up some Ruby ( I know, in the PHP community that is enough to warrant a stoning ). But, it wasn’t totally practical for me to learn a new language and a framework at the same time. I’d been struggling with the framework part enough as is.  And then, as fate might have it, during my PHP vs. Ruby google’s I found it – and by it I mean Laravel.

Laravel – It’s some kind of Panda-Cat-Lemur….thing…

As my search had worn on for a framework with good documentation and support one name kept popping up as new and exciting – it was Laravel. As in most situations in life, finding the thing I wasn’t looking for helped me find exactly what I was looking for. I found that Laravel had good and easier to understand documentation from the start. I was able to get everything setup, including composer (it’s dependency manager), with little to no grief. I had even found some tutorials online that I had planned on working through. On the recommendation of the site, I read through Dayle Rees’s Code Bright book. This thing was a god-send. It was exactly the hand holding I needed to get me through learning a framework and that dude is funny – legitimately.  On top of alllll of that – the syntax within Laravel is way less verbose and far more elegant than what I had experienced in cakePHP. Most methods will allow data passed as an array just like Cake but they also allow you just to comma separate things  instead of saying array(array(array(“mood”=>”bummed”))). The methods are much more clearly arranged and labeled as well. And, finally, using blade templates IS AWESOME. The ability to strip out from everything including methods made me want to cry tears of unbridled joy.


Full disclosure – I’ve not gone through and developed a full app in Laravel yet. I wanted to write this as a synopsis from the total beginners point of view. With that said, I feel like I’ll be sticking to Laravel for a while. It’s been a pleasure so far to learn and it’s so much more intuitive – for me that is. If you swear by CakePHP, I believe you. Everyone chooses their own tool, it’s what you do with it that really counts. I’m sure there are fantastic projects being done in all of these frameworks and that’s exactly what gets me so excited for my own.

Profile picture

Written by Justin Voelkel Dad, developer, tinkerer.