|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Frameworkless\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
6
|
|
|
use Twig_Environment; |
|
7
|
|
|
use Models\User\Base\UserQuery; |
|
8
|
|
|
use Symfony\Component\VarDumper\VarDumper; |
|
9
|
|
|
|
|
10
|
|
|
use Models\User\UserRepo; |
|
11
|
|
|
|
|
12
|
|
|
class IndexController |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var Twig_Environment |
|
17
|
|
|
*/ |
|
18
|
|
|
private $twig; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
* @var \Models\User\UserRepo $UserRepo |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $UserRepo; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* IndexController, constructed by container |
|
28
|
|
|
* |
|
29
|
|
|
* @param Twig_Environment $twig |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Twig_Environment $twig, UserRepo $UserRepo) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->twig = $twig; |
|
34
|
|
|
$this->UserRepo = $UserRepo; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Return index page (/) |
|
39
|
|
|
* |
|
40
|
|
|
* @param array $args |
|
41
|
|
|
* @return Response |
|
42
|
|
|
*/ |
|
43
|
|
|
public function get($args) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
$Users = $this->UserRepo->findMany(); |
|
47
|
|
|
|
|
48
|
|
|
$table = \Donquixote\Cellbrush\Table\Table::create(); |
|
49
|
|
|
$table->addColNames([0, 1, 2]); |
|
50
|
|
|
$table->addClass('table table-striped'); |
|
51
|
|
|
$table->thead() |
|
52
|
|
|
->addRowName('head row') |
|
53
|
|
|
->th('head row', 0, 'Id') |
|
54
|
|
|
->th('head row', 1, 'Имя') |
|
55
|
|
|
->th('head row', 2, 'Email'); |
|
56
|
|
|
$i = 0; |
|
57
|
|
|
foreach ($Users as $User) { |
|
58
|
|
|
$table->addRow($i)->tdMultiple([ |
|
59
|
|
|
$User->getId(), |
|
60
|
|
|
$User->getName(), |
|
61
|
|
|
$User->getEmail()]); |
|
62
|
|
|
$i++; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return new Response($this->twig->render('pages/index.html.twig',[ |
|
66
|
|
|
"table" => $table->render() |
|
67
|
|
|
])); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function add($args){ |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
$User = $this->UserRepo->build(); |
|
73
|
|
|
$User->setEmail('email.ru'); |
|
74
|
|
|
//VarDumper::dump($User); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
try{ |
|
77
|
|
|
$this->UserRepo->save($User); |
|
78
|
|
|
return new Response("success create!"); |
|
79
|
|
|
} catch (\Exception $ex) { |
|
80
|
|
|
return new Response("system error:" . $ex->getMessage()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.