1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Frameworkless\Controllers; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Response; |
6
|
|
|
use Twig_Environment; |
7
|
|
|
use Core\Models\User\UserRepository; |
8
|
|
|
use DebugBar\StandardDebugBar; |
9
|
|
|
use Frameworkless\Helpers\Debug; |
10
|
|
|
|
11
|
|
|
class IndexController |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var Twig_Environment |
16
|
|
|
*/ |
17
|
|
|
private $twig; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
* @var \Models\User\UserRepository $UserRepository |
22
|
|
|
*/ |
23
|
|
|
protected $UserRepository; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
protected $debugbar; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* IndexController, constructed by container |
31
|
|
|
* |
32
|
|
|
* @param Twig_Environment $twig |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
Twig_Environment $twig, |
36
|
|
|
UserRepository $UserRepository, |
37
|
|
|
StandardDebugBar $debugbar |
38
|
|
|
) |
39
|
|
|
{ |
40
|
|
|
$this->twig = $twig; |
41
|
|
|
$this->UserRepository = $UserRepository; |
|
|
|
|
42
|
|
|
$this->debugbar = $debugbar; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Return index page (/) |
47
|
|
|
* |
48
|
|
|
* @param array $args |
49
|
|
|
* @return Response |
50
|
|
|
*/ |
51
|
|
|
public function get($args) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar"); |
54
|
|
|
|
55
|
|
|
$this->debugbar["messages"]->addMessage("hello world!"); |
56
|
|
|
|
57
|
|
|
$Users = $this->UserRepository->findMany(); |
58
|
|
|
|
59
|
|
|
$table = \Donquixote\Cellbrush\Table\Table::create(); |
60
|
|
|
$table->addColNames([0, 1, 2]); |
61
|
|
|
$table->addClass('table table-striped'); |
62
|
|
|
$table->thead() |
63
|
|
|
->addRowName('head row') |
64
|
|
|
->th('head row', 0, 'Id') |
65
|
|
|
->th('head row', 1, 'Имя') |
66
|
|
|
->th('head row', 2, 'Email'); |
67
|
|
|
$i = 0; |
68
|
|
|
foreach ($Users as $User) { |
69
|
|
|
$table->addRow($i)->tdMultiple([ |
70
|
|
|
$User->getId(), |
71
|
|
|
$User->getName(), |
72
|
|
|
$User->getEmail()]); |
73
|
|
|
$i++; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return new Response($this->twig->render('pages/index.html.twig', [ |
77
|
|
|
"table" => $table->render(), |
78
|
|
|
"debugbar_Head" => $debugbarRenderer->renderHead(), |
79
|
|
|
"debugbar_Body" => $debugbarRenderer->render() |
80
|
|
|
])); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function add($args) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
|
88
|
|
|
// $User = $this->UserRepository->build(); |
|
|
|
|
89
|
|
|
//$User->setEmail('email.ru'); |
|
|
|
|
90
|
|
|
//VarDumper::dump($User); |
|
|
|
|
91
|
|
|
|
92
|
|
|
try { |
93
|
|
|
//$this->UserRepository->save($User); |
|
|
|
|
94
|
|
|
|
95
|
|
|
//Faker |
|
|
|
|
96
|
|
|
// $generator = \Faker\Factory::create(); |
97
|
|
|
// $populator = new \Faker\ORM\Propel2\Populator($generator); |
98
|
|
|
// $populator->addEntity('Core\Models\User\User', 5); |
99
|
|
|
// $insertedPKs = $populator->execute(); |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
return new Response("success create!"); |
105
|
|
|
} catch(\Exception $ex) { |
106
|
|
|
return new Response("system error:" . $ex->getMessage()); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..