LAB LAB Catalogo de conocimiento
Volver al catalogo
Articulo Publicado 14/07/2026

Chapter 01: Why creating an MVC Framework

Presentacion del proposito del libro, publico objetivo, entorno necesario y criterios para construir un framework MVC propio.

{sample: true}

Chapter 01: Why creating an MVC Framework

Introducion

On our way to becoming successful developers, we will come across different tools to get the job done. What we learn today will not necessarily be relevant in a couple of years (maybe less). Such is the nature of the beast.

In this changing world, our greatest ability, the one that we must cultivate with greater zeal, is to learn – and UNLearn when necessary -.

Of course, even in this world of rapid change, there are certain things that are more constant.

Let me exemplify the above points.

Take for example the case of frameworks.

A framework is intended to provide the developer with a structure that allows them to write clean code that is easy to scale and maintain. Furthermore, it provides functionality in the form of classes, components, etc; to speed up the work.

Are frameworks absolutely necessary? Of course not. In fact, the creator of PHP himself considers that they are unnecessary and even counterproductive.

Obviously, I disagree, as do many other developers.

I am convinced of the need to use frameworks for different reasons:

If you work on your own, dealing directly with clients for whom applications are developed, the obvious way to maximize profit is to do the greatest amount of work in the least amount of time possible. And in that sense the frameworks as well as the RAD tools are invaluable to generate more income.

If you work as a freelancer, doing outsourced work, you will most likely find that the client already has a product made with some framework; and even if it is a new product, the client will probably have preferences or fixed ideas about the framework to use.

If you work for a company, or aspire to work in one, it is almost unthinkable not knowing how to use one or more frameworks.

You can see that I have used purely economic reasons. This is not because there are not technical ones – there are many – but to be honest, our professional activity must be profitable or we will soon find ourselves doing something else.

However, a "danger", or in any case a concern, when learning a framework, especially for someone with little experience with the language, is to see any problem only depending on the framework used or preferred.

Example: we have been programming in PHP for a couple of months (or less) and we jump head over heels to learn Yii or Laravel or Cake.... Is there something wrong with this? Not at all. But in this case it is more likely that every time we come across a problem, or a new project, we immediately start thinking about things like “what module can I use for this? Which widget will be the most suitable? Again, is there something wrong with this? Not necessarily, but it seems to me that it can make us lose flexibility, and the lack of flexibility IS something dangerous. A lot.

One way to avoid this is to become as competent as possible in the language. This does not mean that we should memorize the syntax and the name of each function – although knowing as much as possible about it does not hurt – but something more important. THE PRINCIPLES and THE PATTERNS.

By principles, I mean the principles that govern object-oriented programming. Those that make our modeling of the problem domain, in terms of the language, more adequate.

By patterns, I mean design patterns that have proven useful in building higher quality products. One of these principles is the Model View Controller (MVC).

The foregoing, seeks to emphasize the fact that, regardless of whether we choose a framework from the various existing ones, the benefit we can get from them (the possibility of extending them, adapting them for our own purposes, or even using only some of its components in case they offer that possibility) will increase exponentially as our knowledge of the language increases.

And this brings us to our next point.

Reasons to create your own MVC framework

Let me insist on some reasons why this is a good idea:

We are in a highly competitive environment such as web development. The pace at which new technologies emerge can be overwhelming, and we cannot afford to be left behind.

It is unlikely – I would say impossible – that we will master all the frameworks with which web applications are developed.

An interesting alternative is to stay on top of new trends, and always skilfully manage a set of tools that allow us to carry out our work efficiently.

Today, I would say that, to be a full stack web developer, we must know:

  • PHP Frameworks: Laravel, Yii, Zend, Cake, Symfony (There are others, but with these we cover a large part of the demand).
  • Version Control: Git with Github or Bitbucket are the standard today.
  • JavaScript frameworks: Angular, React.
  • HTML5, CSS3, Less
  • Databases: MySQL, PostgreSQL, and NoSQL engines like MongoDB

Quite a long list, of course, and even then it's not exhaustive. Now, with respect to PHP frameworks, beyond the preference that one may have for one or the other, the function of all of them is to facilitate the development process. We want to develop more and better, and in this sense they provide us with extraordinary help.

But, and here is the origin of the need, my concern is that we could end up being absorbed by a framework; that we get to look at EACH project from the perspective of the framework and not from the client's needs.

In this sense, if when we start to gather requirements for a project, we start thinking things like “ok, which widget will be appropriate for this?” or "hmm, the xyz framework doesn't allow us to do that", we're in trouble.

We must remember that a framework, however good it may be, is built on a language. In this case, PHP. In addition, it uses design patterns that go beyond this language, such is the case of the MVC pattern (Model View Controller).

For this reason, and in order to take advantage of the power that frameworks give us, but understanding the principles on which they are based, we are going to build our own.

NOTE: The framework we are going to build will start very simple and then progress until it is ready for production. It is an exercise in design and programming, but will see it in action building a real project with it. All the code will be on Github, and if anyone wants to get their hands on it and take it further, they are of course more than welcome to do so.

Who is this book for and how to read it?

As its name suggests, this book is primarily intended for those who want to understand the MVC pattern, and advanced concepts that every professional developer should know. If that is your case, you can skip chapters 02 and 03 entirely.

However, if you are starting from scratch, chapter 02 gives an introduction to the language, which is enough to build the basis.

Chapter 03 deals with object oriented php, presenting concepts and examples that will help you greatly to understand how the paradigm is used to model the real world and build applications.

Installations needed

If you already have a development environment installed and configured, no matter what it is, then you can skip the corresponding chapters and go directly to the ones where the language is started. Nevertheless, I will show you what my environment looks like.

In order to work through the book, we will need:

  • A web server capable of serving php files, such as Apache or IIS.
  • A database server, we will be using MySQL for all our examples.
  • A text editor or IDE to write the code of our applications.

XAMPP

A good option to configure our development environment is to install an application called xampp.

For those who don't know, xampp allows us to configure our local machine with Apache, PHP and MySQL; quickly and easily.

In addition, it is available for all major platforms, so we can use it whether our environment is Windows, Linux or Mac.

The installation process is pretty straight forward. At the end you will have the option to start the control panel (Figure 1) right away:

Xampp Control Panel

Click on Apache and MySQL will start the web and database servers. Then you can type localhost/phpmyadmin on your browser and you should see the following screen (Figure 2):

phpMyAdmin

IDE

If you already have an IDE or text editor of your choice, you can probably work with it without any problem. However, the examples in this book are made using the IDE Visual Studio Code. It is a free and open source application, and it really is excellent.

Errors

Each line of code included in the book has been carefully reviewed. However, errors can occur and in that case I would greatly appreciate being contacted and informed of any problem in order to be able to correct it immediately.

Everyone will benefit from it.

On the other hand, where the code of the example exceeds a few lines of code, in addition to presenting it in the book, I will be providing a corresponding Gist, so that you can refer to that link and copy the code more comfortably if you wish. For those who do not know what a Gist is, it is a way to share files, parts of files and even complete applications. You can find all the relevant information here. Writing the code on your own, following the examples presented, would be an excellent way to gain confidence and get used to the syntax, but you will always have the complete code of the applications to be able to use it.

{blurb, class: warning}

Wordwrap

In certain cases, I had to format my code using two lines where one would be appropriate, in order to avoid line breaks from the wordwrapping in PDF and other formats. The wordwrapping in PDF causes special characters to appear, which break the code, so I had to avoid that the best I could. {/blurb}

Contact information

For any questions regarding this book, as well as for pointing out errors or making suggestions, please send a message to vihugarcia@gmail.com.

I will do my best to answer within 48 hours of receipt.

Summary

This chapter had a lot of discussion and not enough action, but we'll get there. I hope the points exposed served their purpose of presenting the big picture.

In the next chapter we'll begin with the foundations of the language, covering everything you'll need to follow along the book.

See you soon!