forked from dakujem/selectoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamplePresenter.php
More file actions
80 lines (57 loc) · 1.38 KB
/
ExamplePresenter.php
File metadata and controls
80 lines (57 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Dakujem\Selectoo\Examples;
use Nette\Application\Responses\JsonResponse,
Nette\Application\UI\Form,
Tracy\Debugger;
/**
* Example Presenter class.
*
* This Presenter exists purely for example purposes.
*
*
* @author Andrej Rypák <xrypak@gmail.com> [dakujem](https://github.com/dakujem)
*/
class Dkj_ExamplePresenter extends Presenter
{
/** @var Dkj_UserAjaxSelectooFactory */
private $selectooFactory;
/** @var Dkj_UserRepository */
private $repo;
public function injectServices(Dkj_UserRepository $repo, Dkj_UserAjaxSelectooFactory $factory)
{
$this->repo = $repo;
$this->selectooFactory = $factory;
return $this;
}
public function actionDefault()
{
// print out the form
}
/**
*
* https://select2.org/data-sources/formats
*
*
* @param type $q
*/
public function actionApi($q = null)
{
$users = $this->repo->queryUsers($q);
$res = ['results' => $users];
$this->sendResponse(new JsonResponse($res));
$this->terminate();
}
protected function createComponentForm()
{
$form = new Form();
$form->addText('foo', 'Foo');
$form->addText('bar', 'Bar');
$selectoo = $this->selectooFactory->create('Selectoo!');
$form->addComponent($selectoo, 'selectoo1');
$form->addSubmit('go', 'Hello world!');
$form->onSubmit[] = function($form) {
Debugger::barDump($form->getValues(), 'form values');
};
return $form;
}
}