Lately I was assigned to work on a project by using ThinkPHP Framework. This framework is also working as MVC methodology. It is designed by Chinese programmers; however, I am not proud of it at all. I would rather use CodeIgniter or complicated Zend Framework.
The official framework website is here: http://www.thinkphp.cn/
I spent about 2 work days studying this framework , and I found some issues I am not happy with as listed below (using version 2.1).
First of all, it is also the most obvious that Controller is doing too much work that should be done by Model. I was quite annoyed by this issue. I experienced other different PHP frameworks, such as CodeIgniter and Zend. Those frameworks have something in common, and that is Controller can call the classes defined Model area and instantiate the classes to be instances and perform the functions defined within the classes in Model. In this way, it is easy to read the code in both Controller and Model since Controller is showing Actions in organized class instantiating and function calling. Thus, it is quite clear to read and understand the logic behind the theme in Controller. And Model is concentrating on classes and functions definition mainly about SQL interaction. However, in ThinkPHP, all the SQL interaction handling is defined under Controller (called Action in ThinkPHP) area mixed with feature logic flow. With this framework design, Controller is heavily coded and appears to be difficult to understand. ThinkPHP does have the ORG folder to carry extra classes defining other functions, but this could also be included in Model. What Model does in ThinkPHP is to perform some helper-like functionality such as input field check before inserting into database and database field auto-filling. Therefore, ThinkPHP has its own way of defining MVC; however, Model does not do much work as expected to have the total control of class and function definition as a logic center.
Secondly, build-in front-end variables handling (such as volist) can not further modify the variables. After Controller sends the variables to front-end page, ThinkPHP has its own tags to handle array; and the most powerful tag is volist. This “volist” can loop through each item in volist and get each element in each item. For example, if we read a list of users from database and send the user array into front-end page, we can use “volist” to handle each user record as each item; and in each item, we can have read and print each user field from database as each element from each record. Now the main issue is that when looping in volist, each element can not be further edited since all volist tag is under regular html tag with NO PHP tag involved. Thus, we can not further customize each element from each item in volist.
Thirdly, build-in MySQL handling is not smart enough to handle the complicated query. As I mentioned above, the SQL queries are handled in Controller. ThinkPHP has its own syntax for writing and executing queries. Their way of handle MySQL command is quite limited. For example, we have a regular MySQL query “SELECT DISTINCT SUBSTRING(added, 1, 10) FROM table WHERE ….”. In this case, MySQL build-in function SUBSTRING is embedded with selected field “added”. Based on ThinkPHP query syntax, we will have “$result = $table->distinct(‘SUBSTRING(added, 1, 10) ‘)->where(…);”. Sadly, this syntax can not be recognized by ThinkPHP and it returns nothing (no errors). I will still have to use regular MySQL query to get what I want. However, this is not a problem in Zend framework.
So far, other than the stuff I mention above, ThinkPHP is still a choice for developers. It is easy to get things started by setting up and testing the environment. The tutorial document is also well-written.
Hopefully, some time in the future, Chinese programmers can really understand what MVC means and make some serious change and update to make this framework more powerful and make the project under this ThinkPHP framework to be much easier to be organized.