Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
$config['db_username'] = ''; // Database username
$config['db_password'] = ''; // Database password

?>
$config['autoload'] = array(
'plugins' => array(),
'helpers' => array('session_helper', 'url_helper')
);

?>
7 changes: 7 additions & 0 deletions application/controllers/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

class Main extends Controller {

function __construct(){
parent::__construct();
}

function index()
{

$user = $this->session_helper->get('user');

$template = $this->loadView('main_view');
$template->render();
}
Expand Down
34 changes: 33 additions & 1 deletion system/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

class Controller {

function __construct()
{
$this->autoload();
}

private function autoload()
{
global $config;

foreach( $config['autoload'] as $type => $payload )
{
$funcName = 'load' . ucfirst( substr($type, 0, -1) );

if( is_array($payload) )
{
foreach($payload as $toLoad)
{
if(method_exists($this,$funcName))
{
if( $type == 'helpers' )
{
$this->$toLoad = call_user_func(array($this, $funcName), $toLoad);
} elseif( $type == 'plugins' )
{
call_user_func(array($this, $funcName), $toLoad);
}
}
}
}
}
}

public function loadModel($name)
{
require(APP_DIR .'models/'. strtolower($name) .'.php');
Expand Down Expand Up @@ -37,4 +69,4 @@ public function redirect($loc)

}

?>
?>