|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ZfTable ( Module for Zend Framework 2) |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2013 Piotr Duda [email protected] |
|
6
|
|
|
* @license MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace ZfTable\Example\TableExample; |
|
10
|
|
|
|
|
11
|
|
|
use ZfTable\AbstractTable; |
|
12
|
|
|
|
|
13
|
|
|
class Editable extends AbstractTable |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
protected $config = array( |
|
17
|
|
|
'name' => 'Editable table (Db-click on pale yellow space)', |
|
18
|
|
|
'showQuickSearch' => false, |
|
19
|
|
|
'itemCountPerPage' => 10, |
|
20
|
|
|
'showColumnFilters' => true, |
|
21
|
|
|
'rowAction' => '/table/updateRow', |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
protected $headers = array( |
|
25
|
|
|
'idcustomer' => array('title' => 'Id', 'width' => '50'), |
|
26
|
|
|
'name' => array('title' => 'Name', 'filters' => 'text'), |
|
27
|
|
|
'edit1' => array('title' => 'Edit 1', 'editable' => true), |
|
28
|
|
|
'edit2' => array('title' => 'Edit 2'), |
|
29
|
|
|
'surname' => array('title' => 'Surname', 'filters' => 'text'), |
|
30
|
|
|
'street' => array('title' => 'Street', 'filters' => 'text'), |
|
31
|
|
|
'city' => array('title' => 'City'), |
|
32
|
|
|
'active' => array('title' => 'Active', 'width' => 100), |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
public function init() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->getHeader('edit2')->getCell()->addDecorator('editable'); |
|
38
|
|
|
$this->getRow()->addDecorator( |
|
39
|
|
|
'varattr', |
|
40
|
|
|
array('name' => 'data-row' , 'value' => '%s' , 'vars' => array('idcustomer')) |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function initFilters($query) |
|
45
|
|
|
{ |
|
46
|
|
|
if ($value = $this->getParamAdapter()->getValueOfFilter('name')) { |
|
|
|
|
|
|
47
|
|
|
$query->where("name like '%" . $value . "%' "); |
|
48
|
|
|
} |
|
49
|
|
|
if ($value = $this->getParamAdapter()->getValueOfFilter('surname')) { |
|
|
|
|
|
|
50
|
|
|
$query->where("surname like '%" . $value . "%' "); |
|
51
|
|
|
} |
|
52
|
|
|
if ($value = $this->getParamAdapter()->getValueOfFilter('street')) { |
|
|
|
|
|
|
53
|
|
|
$query->where("street like '%" . $value . "%' "); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: