1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require '../../vendor/autoload.php'; |
4
|
|
|
|
5
|
|
|
// grab data from db with PDO or in alternative from your framework ORM |
6
|
|
|
$db = new PDO('mysql:host=HOST_NAME;dbname=DB_NAME;charset=utf8', 'DB_USERNAME', 'DB_PASSWORD', |
7
|
|
|
array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) |
8
|
|
|
); |
9
|
|
|
// data to populate table |
10
|
|
|
$data = $db->query("SELECT id, name, age, phone FROM persons")->fetchAll(PDO::FETCH_OBJ); |
11
|
|
|
// used for column filter |
12
|
|
|
$filterData = $db->query("SELECT name as val, name FROM persons limit 10")->fetchAll(PDO::FETCH_OBJ); |
13
|
|
|
|
14
|
|
|
\Jupitern\Table\Table::instance() |
|
|
|
|
15
|
|
|
->setData($data) |
16
|
|
|
->attr('table', 'id', 'demoTable') |
17
|
|
|
->attr('table', 'class', 'table table-bordered table-striped table-hover') |
18
|
|
|
->attr('table', 'cellspacing', '0') |
19
|
|
|
->attr('table', 'width', '100%') |
20
|
|
|
->column() |
21
|
|
|
->title('Name') |
22
|
|
View Code Duplication |
->value(function ($row) { |
|
|
|
|
23
|
|
|
return rand(1,10)%2 ? '<b>'.$row['name'].'</b>' : $row['name']; |
24
|
|
|
}) |
25
|
|
|
->filter($filterData) |
26
|
|
|
->css('td', 'color', 'green') |
27
|
|
|
->css('td', 'width', '50%') |
28
|
|
|
->css('td', 'background-color', '#ccc') |
29
|
|
|
->add() |
30
|
|
|
->column() |
31
|
|
|
->title('Age') |
32
|
|
|
->value('age') |
33
|
|
|
->filter() |
34
|
|
|
->css('td', 'color', 'red') |
35
|
|
|
->css('td', 'width', '20%') |
36
|
|
|
->add() |
37
|
|
|
->column('Phone') |
|
|
|
|
38
|
|
|
->filter() |
39
|
|
|
->value('phone') |
40
|
|
|
->css('td', 'color', 'red') |
41
|
|
|
->css('td', 'width', '20%') |
42
|
|
|
->add() |
43
|
|
|
->column() |
44
|
|
|
->value(function ($row) { |
45
|
|
|
return '<a href="country/'. $row['id'] .'">edit</a>'; |
46
|
|
|
}) |
47
|
|
|
->css('td', 'width', '10%') |
48
|
|
|
->add() |
49
|
|
|
?> |
50
|
|
|
|
51
|
|
|
<html> |
52
|
|
|
<head> |
53
|
|
|
<!-- JQUERY --> |
54
|
|
|
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> |
55
|
|
|
|
56
|
|
|
<!-- DATATABLES --> |
57
|
|
|
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet"> |
58
|
|
|
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> |
59
|
|
|
|
60
|
|
|
<!-- Bootstrap and Datatables Bootstrap theme (OPTIONAL) --> |
61
|
|
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> |
62
|
|
|
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet"> |
63
|
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> |
64
|
|
|
|
65
|
|
|
<script type="text/javascript"> |
66
|
|
|
|
67
|
|
|
$(document).ready(function(){ |
68
|
|
|
$('#demoTable').DataTable(); |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
</script> |
72
|
|
|
</head> |
73
|
|
|
<body> |
74
|
|
|
<div style="width: 50%; margin: 30px;"> |
75
|
|
|
<?php $table->render(); ?> |
76
|
|
|
</div> |
77
|
|
|
</body> |
78
|
|
|
</html> |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: