Skip to content

Instantly share code, notes, and snippets.

@Jragon
Created November 23, 2012 22:18
Show Gist options
  • Save Jragon/4137553 to your computer and use it in GitHub Desktop.
Save Jragon/4137553 to your computer and use it in GitHub Desktop.
<?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