tailieunhanh - cakephp application development phần 3

Thông thường nhất, một bộ điều khiển quản lý logic cho mô hình duy nhất. Trong chương 3, chúng ta đã thấy như thế nào CakePHP tự động phát hiện ra rằng mô hình có liên quan của tên lớp từ tên của một bộ điều khiển. Các lớp mô hình liên quan đến tự động liên kết | Simpo PDF Merge and Split Unregistered Version - http Controllers Programming Application Logic Interacting with Model Most commonly one single controller manages the logic for one single model. In chapter 3 we already saw how CakePHP automatically finds out that relevant model s class name from a controller s name. The related model class is automatically associated and can be accessed from the controller we don t need to configure it in the controller class explicitly. In the previous chapter we also saw an example of this automatic binding. We created a TasksController class and CakePHP automatically found out and attached the related model Task through its naming convention with the controller. We were able to access the Task model from the TasksController as if that model class is a controller attribute this- Task . Attaching Models and Controllers In CakePHP generally every controller has one dependent model class. That s the way Cake is designed to be used. CakePHP will always look for a related model class for a controller through its naming convention unless a controller-model attachment is explicitly defined in that controller. Now in some unusual situations we may need a controller that does not have any dependency on any model class. In that case we have to configure our controller to handle this scenario. Let s see how such a model-less controller can be created. Time for Action Controller without a Model 1. Put a fresh copy of CakePHP inside your web root folder. Rename the folder to applogic. 2. Inside the app controllers directory create a new PHP file and write the following code inside it. php class BooksController extends AppController var name Books var uses array function index nothing s here 3. Inside the app views directory create a new folder books. Create a new view file named there app views books with the following code h2 Packt Book Store h2 p Coming Soon p 50 Simpo PDF Merge and

TỪ KHÓA LIÊN QUAN