-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathController.php
64 lines (52 loc) · 2.27 KB
/
Controller.php
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
<?php
class Controller{
/* model function called to create an object of a model class
* it checks user login first if not login it'll show login page
* if the user is logged in it'll go on with the request
*/
public function model($model){
require_once '../app/models/Session.php';
global $loggedUser;
$session = new Session;
$loggedUser = $session->checkLogin();
/*
* Comparing the requested model with user status
* if user is loggedin can't request login model
* if user is not loggedin it'll redirect him to login model
*/
if(!$loggedUser && $model != 'Login'){
header('Location: ' . URL . '/' . LANGUAGE .'/home/login');
}elseif($loggedUser && $model == 'Login'){
header('Location: ' . URL . '/' . LANGUAGE .'/home/index');
}
require_once '../app/models/' . $model . '.php';
return new $model();
}
/* view function called to create an object of a view class
* it includes the neccesary language files
* loads the required view.
*/
public function view($view, $data = []){
/*
* A main langauge file called main contains main variables like site name and description in different languages
* every view should have the language file with the same name contains an associative array called
* lang = array('key' => 'value');
* in the language directory
*/
if(!isset($data['lang']['main'])){
require_once("../app/languages/" . LANGUAGE . "/main.php");
/* $lang is an array that is defined in the language file. */
$data['lang']['main'] = $lang;
}
$data['view'] = $view;
if(!isset($data['lang'][$view])){
require_once("../app/languages/" . LANGUAGE . "/". $view .".php");
/* $lang is an array that is defined in the language file. */
$data['lang'][$view] = $lang;
}
//including the header, the view and the footer
require_once '../app/views/layout/header.php';
require_once '../app/views/' . $view . '.php';
require_once '../app/views/layout/footer.php';
}
}