PHP Framework CakePHP (1)
Story Telling
I am designing a simple web app that can possibly improve people’s productivity. Even though it’s supposed to be a fast, light-weight web app, it’s still going to be more complex than most projects I’ve done before. So to get a good start on it, I wanted to try out some PHP frameworks to get started and reuse some common features.
Some of the frameworks that came to my vision was CakePHP, Zend Framework, and Symfony, a PHP-Ajax framework that I came across last year. I chose to give CakePHP a try simply because its homepage looked cute. It’s probably not the best but my product is in prototype phase anyways. I don’t see the possibility of making my app available to general public in any recent future (ie. in 6 months or so, but 6 months is probably enough time to upgrade a small website like this onto a production environment).
MVC-The Essential Design
CakePHP follows MVC design pattern and this might be the design of other frameworks I considered too. It’s still one of the most popular and tangible design patterns among enterprise systems.
Model
One confusion I’ve had with the pattern was that I thought the database was the model, but it turns out that there’s another layer between controllers and database, ie. the models, that wrap up complex SQL into meaningful function calls. And this is where the framework comes in handy. Most basic database operations are implemented in a super class Model. Simply implementing this class will allow model objects to interact with database easily, as member functions such as add, del, and some other helper queries like findAll, and findId etc. I am not very precise on the names but the stuffs are there.
Controller
Classes that implements Controller usually contains handling functions. The framework maps actions extracted from url to functions in corresponding classes. The rule is like this: domain/model/action will map to function action in model_controller. “_controller” is the standard postfix that represents controller of model with name “model”. A typical use, adapted from CakePHP manual, domain/posts/add calls posts_controller->add to add new post.
View
In CakePHP, the view layer are partial html files with file extension .thtml. There’s a overload here between controller and view. For example, in the above section, we know domain/posts/add can handle POST/GET requests to store new post in database, but the url domain/posts/add is also used to access the add new post interface/form. I guess the framework detects POST/GET field in HTTP requests and handle actions before displaying the view.
*I need to check the above statement as I gain more knowledge of the framework.
» Posted in category: web development //
This is the bottom of post PHP Framework CakePHP (1)


