A Coding Writer’s Guide: My Go-To PHP Framework Or Having Your CakePHP & Eating It Too!

As if mastering PHP wasn’t hard enough, diving headfirst into different PHP frameworks can be just as frustrating, especially when you have so many to choose from like: Laravel, Symfony, Phalcon, Slim, PHPixie, and the list goes on and on. In today’s article, I will discuss why I chose to learn CakePHP over all the others. Aside from the sweet sounding name (badum tss), the five other major reasons in my opinion include:

  • CakePHP is simple and easy to install, as you only need a web server and a copy of the framework. In addition, there is great documentation, many support portals, and premium support through Cake Development Corporation.
  • It makes a good choice for commercial applications due to security features that include SQL injection prevention, input validation, cross-site request forgery (CSRF) protection, and cross-site scripting (XSS) protection.
  • Some key features include: a modern framework, fast builds, proper class inheritance, validation, and overall security.
  • CRUD Scaffolding. The CRUD is taken from the main activities involved in most the web applications namely Create, Read, Update, and Delete. It’s useful as it gives you a preliminary view of your application in just a single line of code.The bake.php core library has now changed /console/cake which makes it very easy to modify things as per the specific requirements of your application. The feature might be available in others as well but with CakePHP, it saves a lot of time.
  • Object Relational Mapping. ORM is a programming technique to facilitate data conversion between incompatible type systems in databases and object-oriented programming languages. That is, every table is represented from a class. These classes are responsible for the management of whatever happens with your data, its validity, interactions, and evolution of the information workflow in your domain of work. The built-in ORM of CakePHP specializes in relational databases and can be extended further to support substitute data sources. CakePHP aims at creating a hybrid implementation to create a fast and easy to use ORM.

Bonus Reason: A quick fact about myself, CakePHP was a requirement that a company insisted I have before they would consider taking me on board. To me this is actually the most important reason to learn a particular framework over another. Since many skills throughout programming are transferrable in terms of adaptation, it makes the most sense to take on a popular framework/framework the company employs. Ultimately, it boils down to what the company wants because they write the checks.

Onto what other features make CakePHP great, such as the fact that it open source and also follows the MVC architecture as demonstrated in the image below:

The fact that it is MVC means it takes a Model-View-Controller approach to its design pattern. Why does this matter? Let me illustrate the benefits:

  1. As a consistently reliable software design pattern, it can turn an application into a maintainable, modular, rapidly developed package.
  2. Crafting application tasks into separate models, views, and controllers makes your application very light on its feet. New features are easily added and implemented.
  3. As stated earlier, the modularity also allows developers and designers to work simultaneously on a project.
  4. Separation also allows developers to make changes in one part of the application without affecting the others.

Now before you start baking your next delicious cake project, let’s discuss the layers in a bit more detail that make up this tasty dish!

The Model Layer

The Model Layer is otherwise known as the part of the application that implements the business logic. It is responsible for retrieving data and converting it into meaningful concepts for your application. This includes processing, validating, associating or other tasks related to handling data.

Model objects can be viewed as the first part of interaction with any database you might be using for your application. They stand for the major concepts around which you implement your application.

To use a social networking platform as an example, the Model Layer would take care of tasks such as saving the user data, storing and retrieving user photos, finding suggestions for new friends, and etc.

The View Layer

The View renders a presentation of modeled data and is responsible for using the information it has available to produce any presentational interface your application might need.

For example, as the Model Layer returns a set of data, the View Layer would take it to render a HTML page containing with that particular data set, or a XML formatted result for others to consume, and etc. It can be used to deliver a wide variety of formats depending on your needs, such as videos, music, documents and most any other format you can imagine.

The Controller Layer

The Controller Layer is responsible for rendering a response with the aid of both the Model and the View Layers.

A Controller can be compared to a manager that ensures that all resources needed for completing a task are delegated to the correct workers. It waits for petitions from clients, checks their validity according to authorization rules, delegates data fetching or processing to the model, selects the type of presentational data that the clients are accepting, and finally tells how to render the process to the View.

That’s it!

Now that you have a decent understanding of CakePHP, I highly recommend you jump into the deep end start building! Or if that didn’t convince you and you’d rather learn a different framework, then I suggest anything else from the list I provided at the beginning of this article. Learning any framework is beneficial to your career trajectory as a programmer. Always code, code, code!

Founder of Neo Typewriter. He is a published author, podcast host, digital marketer, and full-stack web developer. Read more at: www.andrewjly.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store