Nowadays PHP frameworks like Laravel, Codeigniter are getting popular every day. Thanks to these frameworks PHP itself also updating quickly. Most of the projects these days are using PHP developed using any on these frameworks. I, myself am a Laravel developer with core PHP. I developed many projects using Laravel and it is really nice and easy to use. But I noticed a problem with not only Laravel but with some other PHP frameworks also. That is Laravel is good for any kind of project, but it is a heavy-weighted framework. When I was working on some small-scale projects, I thought that it is unnecessary to use such a heavy framework like Laravel for those projects. So, I searched for any other lightweight frameworks for PHP and found so many frameworks like SlimPHP, FuelPHP, etc., and Laravel itself providing a lightweight framework called Lumen. Those frameworks are really good and attractive, but still, I am not satisfied with those frameworks. The problem I noticed is most of the well-known frameworks keep their core hidden so that only pro developers can understand and access it. Those who are beginners or intermediate developers can't able to modify the core due to the fear of breaking the application. I really annoyed by this problem and for some projects, I worked with Core PHP. While working with core PHP, I used to get confused with the structures of the modules. Sometimes my teammates used to mix the structure to reduce the work time. So I used to clean the structure every time I worked on it. This continued until the end of that project. After finishing the project I decided to develop my own project structure so that I can apply it for my every small-scale project. That's how the idea of my own PHP framework was born.
In this project, my goals are simple. They are:
- The framework should be lightweight which will be used for both small-scale and large-scale projects.
- The core of the framework will be accessible by any developer. In simple these will be no core for the project, so that developer can use it as his wish.
- The framework is clean MVC structured.
Finally, after so many combinations and structures, I succeeded with my framework. I'll tell you what I did.
MVC stands for Models, Views, and Controllers. Every MVC framework will follow the rules of Object-Oriented Programming. There are 4 main things in every MVC framework.
Routes will handle the URLs while controllers handle the actions and Models will be used to interact with the database and views are HTML coded which will be displayed at the end. In my framework, I used the AltoRouter package for routing, it's a very good package and well documented. And for database Interaction in the Models, I used Mysqli Object Oriented. And both Models and Views will be accessed by the controller.
Facades are the helper classes which is developed to reduce the process of typical functionalities. These features were adopted by Laravel. There are 6 Facades will be available in the framework. Those are:
- Crypt: Used for encryption and decryption.
- Mail: Used for sending emails.
- Request: Used to handle GET, POST, AJAX requests.
- Validation: Used for form validations.
- File: Used for file uploads.
- DB: Used for database connections.
The framework will be supported by three different modes.
The configuration of these 3 modes is different and will not collide with each other. This kind of functionality is adopted from FuelPHP. The mode will be configured in the main variables file env.php. Like Laravel and every other framework, I used environmental variables in this framework also. But unlike any other .env files I used a normal PHP array which is configured in env.php.
I used some external PHP packages in my framework which are listed below.
And then the framework is completed. For clear documentation about the framework, please check the Github repository. https://github.com/bhaswanth53/ynotphp.