- CakePHP 1.3 Application Development Cookbook
- Mariano Iglesias
- 251字
- 2021-04-09 22:04:17
This recipe shows how to use Containable
to change the conditions used to fetch data related to a model through a binding.
We need to have Containable
added to our models, and we also need some sample models and data to work with. Follow the recipe, Adding Containable to all models, and the Getting ready section of the recipe, Modifying binding parameters for a find.
If we want to obtain the first User
record together with the published Article
records that user owns, but ordered by latest articles first, and limiting some of the returned fields, we use the conditions
binding setting:
$user = $this->User->find('first', array(
'contain' => array(
'Article' => array(
'fields' => array('Article.title'),
'conditions' => array( 'Article.published' => 1 )
)
)
));
Using our sample data, the preceding query will result in the following array structure:
array( 'User' => array( 'id' => '1', 'name' => 'John Doe', 'email' => 'john.doe@example.com', ), 'Article' => array( array( 'title' => 'John\'s Post 1', 'user_id' => '1' ), array( 'title' => 'John\'s Post 2', 'user_id' => '1' ), array( 'title' => 'John\'s Post 4', 'user_id' => '1' ) ) )
The conditions binding setting is another binding parameter, such as those shown in the recipe, Modifying binding parameters for a find. As such, the Containable
behavior uses the built-in bindModel()
method defined in CakePHP's Model
class to alter the binding conditions defined in the contain
find operation.
- Moldflow 2010完全自學與速查手冊(模流分析·成本控制)
- Cacti 0.8 Beginner's Guide
- AutoCAD 2018中文版基礎教程
- Photoshop CC摳圖+修圖+調色+合成+特效實戰視頻教程
- ANSYS Workbench中文版超級學習手冊
- Spark Cookbook 中文版
- Autodesk Ecotect Analysis綠色建筑分析應用
- Photoshop CC完全自學教程:從入門到實踐(全新版)
- Cinema 4D基礎與實戰教程
- Photoshop CS6平面設計實戰從入門到精通(經典暢銷版)
- 科技繪圖/科研論文圖/論文配圖設計與創作自學手冊:科研動畫篇
- After Effects 影視后期特效:短視頻制作實戰寶典
- 老郵差Photoshop數碼照片處理技法蒙版篇(第2版)
- AutoCAD計算機輔助設計標準教程(慕課版)
- 設計+制作+印刷+商業模版:InDesign實例教程