ladogton2010 commited on
Commit
235bfe8
·
1 Parent(s): 789f143

Test Controller class

Browse files
mvc/app/controllers/Welcome.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
- class Welcome{
3
  public function __construct(){
4
  }
5
 
6
  public function index(){
7
- echo('index loaded');
8
  }
9
 
10
  public function test($data){
 
1
  <?php
2
+ class Welcome extends Controller{
3
  public function __construct(){
4
  }
5
 
6
  public function index(){
7
+ $this->view('welcome/index');
8
  }
9
 
10
  public function test($data){
mvc/app/libs/Controller.php CHANGED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Controller{
3
+ public function __construct(){
4
+
5
+ }
6
+
7
+ public function model($model){
8
+ require_once('../app/models/' . $model . '.php');
9
+
10
+ return new $model();
11
+ }
12
+
13
+ public function view($view, $data = []){
14
+ if (file_exists('../app/views/' . $view . '.php')) {
15
+ require_once('../app/views/' . $view . '.php');
16
+ }
17
+ else{
18
+ die('View not found');
19
+ }
20
+ }
21
+ }