I am a PHP web developer. I use frameworks a lot while development. I am active in various forums to learn new things and to help other people. What I don’t know, I ask them. Whatever I know, I help them. And the process goes on.
I have seen that lot of people from vanilla PHP background found same issues while developing application using PHP framework. People from vanilla PHP background putting vanilla code all the time in the framework even if framework have very nice and shortcut utilities to achieve the task.
What are the basic features any framework provide?
- Folder Structure (MVC or any other)
- REST api
- Database Utilities (Active Records, ORM)
- File Upload
- Request & Response
- Server-side validations
What people are doing wrong?
People try to invent wheel within the wheel.
We learn by example. Every framework have nice utility to upload the files. You just have give some configuration like file mime-type, path etc and after calling a simple function your file get uploaded on the desired path. But people using regular code inside the framework and create the mess. Just take example of CodeIgniter framework. They have nice utility to upload the files, but still some people writing vanilla php code to upload documents in Controllers.
Lets take other example of database queries and MVC architecture. According to MVC, we need to write each and every database related transactions in Models. Lot of people write queries directly in controllers or views, and that’s the mistake. Code executes successfully but then no meaning in using the MVC structure.
Also, framework (e.g. CodeIgniter) having database utilities for Insert, Update, Delete, Pull the data. CodeIgniter provides active-record queries to do that thing. Still lot of people write basic queries, and escape sequences to prevent sql injection, which is again unnecessary code.
What are the best practices with frameworks?
Read the documentation. Yes, we as a responsible developer need to read the documentation first, then start to building applications in frameworks. Every framework have the list of basic feature which are given above. If the features not their, then atleast their is scope of adding some php extensions to achieve those. After reading documentation, we will get clear idea about how to use that framework effectively.
We can cut the wood faster with saw than axes if we use is correctly, even if saw is less powerful and thinner than axes.