PHP FRAMEWORK – Web Programming and Web Database Asst. Prof. Dr. Choopan Rattanapoka
What is a PHP Framework PHP frameworks streamline the the development of web applications written in PHP by providing a basic structure for which to build the web applications. In other words, PHP frameworks help to promote rapid application development (RAD), which saves you time, helps build more stable applications, and reduces the amount of repetitive coding for developers. Frameworks can also help beginners to build more stable apps by ensuring proper database interaction and coding on the presentation layer. This allows you to spend more time creating the actual web application, instead of spending time writing repetitive code The general idea behind the workings of a PHP framework is referred to as Model View Controller (MVC)
Why should we use a PHP Framework Developers should utilize PHP frameworks for various reasons. Speeding up the development process. Stability. PHP Framework 2013
Model-view-Controller (MVC)
ตัวอย่าง : CodeIgniter Framework The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter. The Router examines the HTTP request to determine what should be done with it. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution. Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security. The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request. The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.
รูปแบบ URL method]/[arguments] เช่น ชื่อ Controller คือ news ชื่อ Method คือ latest มีการส่ง argument คือ 10
Controller ( ปกติจะเก็บใน folder: Controller) You have created a class named Pages, with a view method that accepts one argument named $page. The Pages class is extending the CI_Controller class. This means that the new pages class can access the methods and variables defined in the CI_Controller class (system/core/Controller.php)
View ( ปกติจะเก็บไว้ใน folder: view) CodeIgniter Tutorial © 2015 application/views/templates/header.php application/views/templates/footer.php
ทำให้ Controller เชื่อมต่อกับ View ได้ แล้วก็สร้าง application/views/home.php เอาไว้ใส่ข้อความ อะไรก็ได้ ปรับเปลี่ยน Controller ให้มีการ load หน้า view
Model ปกติจะเก็บไฟล์ไว้ที่ application/models
ทำให้ Controller สามารถเชื่อมต่อ Model ได้
ปรับแต่งหน้า view เพื่อแสดงข้อมูลจาก Controller