I was recently exploring some projects available on Internet built with php. There are tons of small projects, extensions and plugins easily available on Internet with specific tasks. Many newbies can easily get these codes and use them in their project, that is how PHP are said to be easy as there is thousands of extensions and plugins available ready to be used.
What do I mean by Bad practice and unmanaged codes ?
However Its very easy to build a website with these codes but using different kind of coding practice form different sources from different modules of your application is gonna get you nowhere. For example if you want to display a page and using "echo" to display html codes line by line and using built in functions directly on the front-end page then it will creates confusion with the front end and back functionality. It may be easy and faster way to design small pages with little server side scripting but as your website grow, its gonna be a nightmare for you to debug it if you get trapped with some bugs.
How should we actually write PHP codes ?
The answer is simple 'keep front end and server side scripts completely separate'. But thats not all. Try to develop with MVC even with the smallest project. Keeping your model, view and controller in separate files and folders will give you better speed and control. It also lets you easily scale your project and applications are gonna be likely anomaly free. I would also suggest to use framework there are many good framework available for both small and large systems.
some popular PHP frameworks are..
1. Codeigniter
2. Cakephp
3. Yii
4. Zend
Common mistake while using framework
Using an MVC framework isn't gonna solve all your problems. People still tends to use library functions available for front end designing like forms etc. This kind of practice is bad for responsive web site specially if you want your website to open smoothly of different devices (Mobile , Tab and different browsers). So I would suggest to develop the front end using only front end technology like HTML5 , CSS. Jquery or Angular js. And keep all the back-end codes in separate files.
Benefits of Using PHP framework
Have a great time with PHP .........
What do I mean by Bad practice and unmanaged codes ?
However Its very easy to build a website with these codes but using different kind of coding practice form different sources from different modules of your application is gonna get you nowhere. For example if you want to display a page and using "echo" to display html codes line by line and using built in functions directly on the front-end page then it will creates confusion with the front end and back functionality. It may be easy and faster way to design small pages with little server side scripting but as your website grow, its gonna be a nightmare for you to debug it if you get trapped with some bugs.
How should we actually write PHP codes ?
The answer is simple 'keep front end and server side scripts completely separate'. But thats not all. Try to develop with MVC even with the smallest project. Keeping your model, view and controller in separate files and folders will give you better speed and control. It also lets you easily scale your project and applications are gonna be likely anomaly free. I would also suggest to use framework there are many good framework available for both small and large systems.
some popular PHP frameworks are..
1. Codeigniter
2. Cakephp
3. Yii
4. Zend
Common mistake while using framework
Using an MVC framework isn't gonna solve all your problems. People still tends to use library functions available for front end designing like forms etc. This kind of practice is bad for responsive web site specially if you want your website to open smoothly of different devices (Mobile , Tab and different browsers). So I would suggest to develop the front end using only front end technology like HTML5 , CSS. Jquery or Angular js. And keep all the back-end codes in separate files.
Benefits of Using PHP framework
- Easy to debug.
- Increase scalability of applications.
- Fast development with the help of libraries.
- Secure Codes and best practice enforced.
- Better designing and demonstration of application.
Have a great time with PHP .........