1 | <?php |
||
12 | class EditUserForm extends FormModel |
||
13 | { |
||
14 | /** |
||
15 | * Constructor injects with DI container. |
||
16 | * |
||
17 | * @param Anax\DI\DIInterface $di a service container |
||
18 | */ |
||
19 | 1 | public function __construct(DIInterface $di, $id) |
|
20 | { |
||
21 | 1 | parent::__construct($di); |
|
22 | 1 | $this->user = new User(); |
|
|
|||
23 | 1 | $this->user->setDb($this->di->get("db")); |
|
24 | 1 | $this->user->find("id", $id); |
|
25 | $user = $this->user; |
||
26 | $this->form->create( |
||
27 | [ |
||
28 | "id" => __CLASS__, |
||
29 | "fieldset" => true, |
||
30 | "legend" => "Update user: $user->name" |
||
31 | ], |
||
32 | [ |
||
33 | |||
34 | "name" => [ |
||
35 | "type" => "text", |
||
36 | "readonly" => true, |
||
37 | "value" => $user->name, |
||
38 | ], |
||
39 | "email" => [ |
||
40 | "type" => "text", |
||
41 | "value" => $user->email, |
||
42 | ], |
||
43 | "select" => [ |
||
44 | "type" => "select", |
||
45 | "label" => "Select authority", |
||
46 | "options" => ["$user->authority" => $user->authority, "admin" => "admin", "user" => "user"], |
||
47 | ], |
||
48 | "submit" => [ |
||
49 | "type" => "submit", |
||
50 | "value" => "Update", |
||
51 | "onclick"=>"return confirm('Fick du verkligen allt rätt?');", |
||
52 | "callback" => [$this, "callbackSubmit"] |
||
53 | ], |
||
54 | ] |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Callback for submit-button which should return true if it could |
||
61 | * carry out its work and false if something failed. |
||
62 | * |
||
63 | * @return boolean true if okey, false if something went wrong. |
||
64 | */ |
||
65 | public function callbackSubmit() |
||
83 | } |
||
84 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: