File tree Expand file tree Collapse file tree 5 files changed +36
-6
lines changed Expand file tree Collapse file tree 5 files changed +36
-6
lines changed Original file line number Diff line number Diff line change
1
+ DB_PASS = mypassword
Original file line number Diff line number Diff line change 7
7
8
8
class HomeController
9
9
{
10
- public function index ():string
10
+ public function index ():View
11
11
{
12
- return ( new View ('index ' ))-> render ( );
12
+ return View:: make ('index ' , [ ' foo ' => ' test ' ] );
13
13
}
14
14
15
15
public function upload ()
Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Controllers ;
4
4
5
+ use App \View ;
6
+
5
7
class InvoiceController
6
8
{
7
- public function index (): string
9
+ public function index (): View
10
+ {
11
+ return View::make ('invoices/index ' );
12
+ }
13
+ public function create (): View
8
14
{
9
- return ' InvoiceController ' ;
15
+ return View:: make ( ' invoices/create ' ) ;
10
16
}
11
- public function create (): string
17
+ public function store ()
12
18
{
13
- return 'Create ' ;
19
+ $ invoice = new Invoice ();
20
+ $ amount = $ _POST ['amount ' ];
21
+ $ invoice ->store ($ amount );
22
+ var_dump ($ amount );
14
23
}
15
24
}
Original file line number Diff line number Diff line change @@ -16,15 +16,34 @@ public function __construct(
16
16
){
17
17
}
18
18
19
+ public static function make (string $ view , array $ params =[]) : static
20
+ {
21
+ return new static ($ view ,$ params );
22
+ }
23
+
19
24
public function render (): string
20
25
{
21
26
$ filePath =VIEW_PATH .'/ ' .$ this ->view .'.php ' ;
22
27
if (!file_exists ($ filePath )){
23
28
throw new ViewNotFoundException ();
24
29
}
25
30
31
+ // foreach ($this->params as $key=> $value){
32
+ // $$key=$value;
33
+ // }
34
+
35
+ extract ($ this ->params );
26
36
ob_start ();
27
37
include $ filePath ;
28
38
return (string ) ob_get_clean ();
29
39
}
40
+
41
+ public function __toString (): string
42
+ {
43
+ return $ this ->render ();
44
+ }
45
+ public function __get (string $ name )
46
+ {
47
+ return $ this ->params [$ name ] ?? null ;
48
+ }
30
49
}
Original file line number Diff line number Diff line change
1
+ <?php echo $ foo?>
1
2
<form action="/upload" method="post" enctype="multipart/form-data>">
2
3
<input type="file"name="recipt">
3
4
<button type="submit">Upload</button>
You can’t perform that action at this time.
0 commit comments