và có thể được truy cập từ bộ điều khiển chúng ta không cần cấu hình nó trong lớp điều khiển một cách rõ ràng. Trong chương trước, chúng tôi cũng nhìn thấy một ví dụ về ràng buộc này tự động. Chúng tôi tạo ra một lớp TasksController và CakePHP tự động phát hiện ra | Simpo PDF Merge and Split Unregistered Version - http Chapter 5 In CakePHP the equivalent query can be performed by calling its find method like the following find all array conditions array LIKE A fields array order DESC limit 2 Prefixing conditions with the model s name like rather that just title is always a good practice. Particularly when we were fetching related model data discussed in Chapter 5 and two or more columns of the result have the same field name. Moreover it improves clarity of the code. The find method takes two parameters type and constraints. The first one type is a string that defines the type of the query. type can be set to one of the following all The method returns all the records that matches the given conditions sorted by the given order and up to the given limit. first The method returns only the first record that matches the given constraints. count The method returns the total number of records returned by the query. As we saw in the last example we can specify other query constraints in the second parameter constraints as an associative array. The constraints associative array can have the following keys conditions An array of the conditions that will be applied to the WHERE clause of the query. Default is 1 1 which means no condition is applied. fields An array of the fields to be returned by the query. If nothing is specified it will return all the fields. This parameter is not applicable when the first parameter type of the find function is set to count. 83 Simpo PDF Merge and Split Unregistered Version - http Models Accessing Data order A string that defines the ORDER BY clause of the query. If order is not specified there will be no ORDER BY clause added to the query. This parameter is also not applicable when the type of the function is count. limit An integer that specifies maximum number of records to return. If not .