1 | <?php |
||
9 | class EndpointController extends DemoController |
||
10 | { |
||
11 | public function anyIndex() |
||
12 | { |
||
13 | // load the data |
||
14 | $model = Article::findOrNew(1); |
||
15 | |||
16 | // instantiate the form |
||
17 | $form = new Endpoint($model); |
||
18 | |||
19 | // define the fields |
||
20 | $form->text('title')->rules('required|max:10'); |
||
21 | $form->text('author.firstname', 'Author\'s first name') |
||
22 | ->rules('required'); |
||
23 | $form->text('author.lastname'); |
||
24 | $form->textarea('detail.note'); |
||
25 | $form->textarea('body'); |
||
26 | $form->select('public')->options([ |
||
27 | 0 => 'No', |
||
28 | 1 => 'Yes', |
||
29 | ]); |
||
30 | |||
31 | // read the POST data, if any |
||
32 | $form->populate(); |
||
33 | |||
34 | // write new data back to the model |
||
35 | $form->writeSource(); |
||
36 | |||
37 | // if the form has been sent, and has no errors |
||
38 | if ($form->submitted() && $form->validate()) { |
||
39 | // we will save the data in the database |
||
40 | $form->save(); |
||
41 | } |
||
42 | |||
43 | // we just need to pass the $form instance to the view |
||
44 | return $form->toArray(); |
||
45 | } |
||
46 | |||
47 | } |
||
48 |