Created
November 23, 2012 22:18
-
-
Save Jragon/4137553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Load{ | |
function __construct($object){ | |
$this->object = $object; | |
} | |
// loads a specified model | |
public function model($model){ | |
$model = strtolower($model); | |
if(file_exists(APPPATH . "models/$model.php")){ | |
require(APPPATH . "models/$model.php"); | |
$modelclass = ucfirst($model . '_Model'); | |
// call function to include it in the object | |
$this->object->$model = new $modelclass; | |
} | |
} | |
// loads a veiw | |
public function view($view, $data = NULL){ | |
// asign filepath | |
$path = APPPATH . "views/" . $view . ".php"; | |
// asign variables if $data is set | |
if($data != NULL) | |
foreach($data as $var => $value) | |
$$var = $value; | |
if(file_exists($path)){ | |
ob_start(); | |
require($path); | |
print(ob_get_clean()); | |
}else | |
return false; | |
} | |
// load a library | |
public function library($library){ | |
$library = strtolower($library); | |
if(file_exists(LIBRARY . "$library.php")){ | |
require(LIBRARY . "$library.php"); | |
$libraryclass = ucfirst($library); | |
$this->object->$library = new $libraryclass; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment