Development

/plugins/sfGridPlugin/trunk/lib/routing/sfGridRoute.php

You must first sign up to be able to contribute.

root/plugins/sfGridPlugin/trunk/lib/routing/sfGridRoute.php

Revision 29131, 1.1 kB (checked in by Leon.van.der.Ree, 3 years ago)

updated interfaces of grids, adding routing-class for grids

Line 
1 <?php
2
3 /**
4  * sfGridRoute represents a route that is bound to a Grid-class.
5  *
6  * A grid route can only represent a single Grid object.
7  *
8  * @package    symfony
9  * @subpackage routing
10  * @author     Leon van der Ree
11  * @version    SVN: $Id:  $
12  */
13 class sfGridRoute extends sfObjectRoute
14 {
15   public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array())
16   {
17     $options['type'] = 'object';
18
19     parent::__construct($pattern, $defaults, $requirements, $options);
20   }
21  
22   protected function getObjectForParameters($parameters)
23   {
24     $className = $this->options['model'];
25     $grid = new $className();
26     
27     if (!$grid instanceof sfContextGrid)
28     {
29       throw new InvalidArgumentException('The model should extend sfContextGrid');
30     }
31     
32     if (isset($parameters['page']))
33     {
34       $grid->setPage($parameters['page']);
35     }
36     
37     if (isset($parameters['sort']))
38     {
39       $sort = $parameters['sort'];
40       $type = isset($parameters['type']) ? $parameters['type'] : null;
41       
42       $grid->setSort($sort, $type);
43     }
44         
45     return $grid;
46   }
47 }
48
Note: See TracBrowser for help on using the browser.