The Research of PHP Development Framework Based on MVC Pattern

INTRODUCTION The rapid development of the internet for web application development brought forward a higher demand of efficiency, reliability, maintainability and scalability. PHP has features of intuitive, easily top of hand, run fast, crossplatform, open source, etc. [1] [2], thus it became one of the most important Web development language. While, the PHP development model mixes the code of data access, the processing of business logic ,and web presentation layer together, as a relult, it brough about many problems in the web applications . MVC design pattern is a proven effective way of the generation of organized modular applications, [3]. As a design pattern, MVC is common to split an application into separate layers that can be analyzed, and sometimes implemented, separately. By decoupling models and views, MVC helps to reduce the complexity in architectural design and to increase flexibility and reuse of code. This study will propose a development framework of PHP based on the MVC design model, which might be an effective separation of data access, logic processing and user interface, and thus it could promote the efficiency and quality of PHP development.

THE STRUCTURAL DESIGN OF FRAMEWORK A. The architecture of framework This framework applied the five B / S structure of the MVC model, web layer corresponds to the viewer and controller, Business logic tier and data persistence layer were fulfilled by the model.

Model: It is the domain-specific representation of the data on which the application operates. Domain logic adds meaning to raw data. Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the model. View: Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. Controller: Processes and responds to events (typically user actions) and may indirectly invoke changes on the model. B. The operation process of framework Client send request to the server, server-side use of the only entrance – the front-end controller of the user’s request for mapping, with the user request to find the corresponding action, action controller analyzes the contents of the request and call the appropriate model for business logic processing and data visit, then to transmit the results to the view layer, lastly, let the view layer load the view template to deal with the logic displayed and respond to the user through the frontend controller.

THE REALIZATION OF FRAMEWORK A. View Technology The key of view is separate the code of PHP and HTML by template [5]. The template file will need to dynamically display the contents of the definition in the form of a variable, sent to the template data analysis engine after processing logical display layer , generate end-user view by replacing the template variables. The framework builts Smarty Templates technology inner. Programmers merely to extract, organize and disposal the data needed, and then through the smarty template engine to handle the assignment. Thus we may detach the programmed code and HTML entirely[6]. It not only reduces the complexity of development, but also do benefit to the collaboration and division. Dual-caching technology was induced to the framework. After the developers designing the template file (or modify the template file), the system firstly calls the appropriate view of the model to obtain the necessary data, and then loads the template engine and compile those to the user view ,finally to cache them. In addition, the framework stored the user view statically to HTML files furthermore. In this case, when a URL was accessed for the first time, the system merely need to perform the action of calling model, anglicizing the template file, the process of generating HTML documents; and yet, the following visiting to the URL can be directly targeted to the static HTML document, to save a lot of re-compelling and reading time, so that improved speed and efficiency of the program far more.

B. The design of controller Controller is responsible for receiving user requests, updating models, and selecting the right view to return to the user. Controller helps to model layer and the view layer separation, resulting in the same model developed on the basis of a wide variety of views. The design of framework controller can be divided into two parts, front controller and action controller. Front-end controller is mainly responsible for analysis of user’s requests and forwards the user requests to the appropriate controller action processing. Action controller is mainly answer for calling the feat model generation for the view of the use of data. Front controller -Index.php is the only entrance to the framework, through the Apache server configuration rewriting engine, which can ensure that all pages have reached the front controller’s requests, in order to achieve the centralized control of framework. Therefore, in addition to analysis of forwarding the user request, the front controller can also be easily achieved: authentication, logging)and data validation and other functions.

C. Data Manipulation PHP supports a wide range of database, and yet the database interface supports offered by PHP are non-uniform [7]. Framework applied the PDO (PHP Data Object) as a database abstraction layer of the foundation, in order to increase the portability of code. PDO aims to supply an uniformed API of common functions for most relational databases. This greatly simplifies the PHP process (through the package differences in a common API to support different database) development. C. Data Manipulation PHP supports a wide range of database, and yet the database interface supports offered by PHP are non-uniform [7]. Framework applied the PDO (PHP Data Object) as a database abstraction layer of the foundation, in order to increase the portability of code. PDO aims to supply an uniformed API of common functions for most relational databases. This greatly simplifies the PHP process (through the package differences in a common API to support different database) development.

In addition, the framework also has an effective and powerful text processing feature, and supports for Perl regular expressions, XML document parsing and so on. Moreover, developers can easily get implemented in the framework of text data in the database, like insert, modify, delete, query and other basic operations through a simple code and work.