Please share your favorite application design / design patterns for use in PHP with me. Some things I'd like to know:
You don't have to answer all of these, answering any or a few of these will be helpful.
The reason I'm asking this,is because I'm very tired of writing repetitive, ugly code in PHP and I want to make a small framework for my freelancing projects which will make programming easier and let me focus on the challenging/business tasks rather than form validation, pagination, and the other mundane activities which make up 80% of programming work in PHP
All opinions appreciated!
The Singleton Design Pattern That prevents multiple instances from being active at the same time which could cause weird bugs. Most of the time this gets implemented in the constructor. The goal of the singleton pattern is typically to regulate the global state of an application.
Adapter (Structural) The adapter pattern (or sometimes known as a wrapper) is one of the most useful and most popular design patterns in software engineering. This pattern seeks to solve the problem of incompatible interfaces between a client and a service provider.
Factory method is a creational design pattern which solves the problem of creating product objects without specifying their concrete classes. The Factory Method defines a method, which should be used for creating objects instead of using a direct constructor call ( new operator).
I might get voted down for this, but if you really do want to write your own framework, I say go for it because you will learn a lot from the experience. The other frameworks mentioned here are great and tested and you wouldn't be making a bad decision using them, but it's your choice.
Before starting to write your framework, look at the other frameworks (at their syntax, directory structure, naming schema, design patterns, etc) and try to figure out why they did what they did and what, if anything, you would do differently. Try out a few tutorials and play with their code, make a few sample apps. If, after doing that, you don't like using them, then go ahead and start planning your framework, keeping what worked and improving what didn't.
If you do decide to roll your own, here are a few things I would recommend from my own experience:
I have to agree with the above posters. If you're not using a framework when programming in PHP you're really programming with your hands tied behind your back. I personally recommend CodeIgniter. It's the fastest framework around, it's very easy to learn, and has a very active community. All of your questions will be answered by the framework:
* How your folders are designed
CodeIgniter (or any framework for that matter) separates your logic into views, models, and controllers, each with their own folder.
* Do you have a standard way of dealing with CRUD, pagination, or any other common tasks?
CI has a pagination library, and it has 3rd party libraries like DataMapper for wrapping your CRUD calls in an object oriented way (ORM).
* What are ways in which you can make your code more elegant?
The seperation of the model, view, and controller make for very elegant code.
(The 2 questions I didn't answer are pretty much implied when using the framework)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With