Bouncy Melons 0.2
declarative style orm
list.php
Go to the documentation of this file.
1 <?php
2 
3 namespace bm\example;
4 
5 /*
6  * declare list of bottles
7  */
8 class WineBottles extends \bm\DataList {
9 
10  /*
11  * overridde abstract method \bm\DataList::createSingle()
12  * to create single bottle object
13  */
14  public function createSingle() {
15  return new WineBottle();
16  }
17 
18  /*
19  * setup view name, optional, by default class name with siffix _view will be used
20  * winebottles_view in our case
21  */
22  public function getViewName() {
23  return "my_view";
24  }
25 
26  /*
27  * change default view, to add calculated fields, see single.php
28  */
29  public function declareView() {
30  /*
31  * init another table to be joined
32  */
33  $brands = new Brands();
34 
35  /*
36  * create or modify view
37  */
38  $this->createViewAs("
39  SELECT
40  tBottles.*, FLOOR(RAND()*100) AS `random`,
41  tBrands.title AS `brand`, tBrands.id AS `brand_id`
42  FROM
43  `".$this->getTableName()."` as tBottles
44  LEFT JOIN
45  `".$brands->getTableName()."`as tBrands ON (
46  tBottles.brand = tBrands.id
47  )
48  ");
49  }
50 }
getTableName()
Definition: DataList.php:13
createViewAs($sql)
Definition: DataList.php:181