CakePHP 1.2 - Life Made A Lot Simpler for PHP Programmer
By admin on Mar 24, 2008 in Programming, php
I have been using CakePHP 1.1 for few projects, and now I am so used to it and tend to use it for every PHP project that I am doing. CakePHP 1.2 is still in beta but more features are incorporated into the core. One of the features that I think should be part of the core even much earlier will be the pagination feature.
The improved Cake shell can help to generate the model, view and controller with pagination. Here is a code snippet generated and modified using the bake shell
1: var $paginate = array(
2: ‘limit’ => 25,
3: ‘order’ => array(
4: ‘Txn.txn_dt’ => ‘desc’
5: )
6: );
7:
8: function index($id = null) {
9: if (!empty ($this->data)) {
10: $counter_query = array
11: ("or" =>
12: array
13: (
14: "lower(Counter.name)" =>
15: "like %".low($this->data[‘id’])."%",
16: "Counter.code" => $this->data[‘id’]
17: )
18: );
19: $this->Txn->recursive = 0;
20: $this->set(‘txns’, $this->paginate(
21: null,$counter_query,null));
22: $this->set(‘counter’, $this->data[‘id’]);
23: } else {
24: $this->Txn->recursive = 0;
25: $this->set(‘txns’, $this->paginate());
26: }
27: }
As you can see, it is fairly easy to do pagination in CakePHP 1.2. I can even specify the behaviors using the $paginate variable.
