diff --git a/application/config/config.php b/application/config/config.php index d34579b..ad21da2 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -10,4 +10,9 @@ $config['db_username'] = ''; // Database username $config['db_password'] = ''; // Database password -?> \ No newline at end of file +$config['autoload'] = array( + 'plugins' => array(), + 'helpers' => array('session_helper', 'url_helper') +); + +?> diff --git a/application/controllers/main.php b/application/controllers/main.php index b1c40ac..4f6d31a 100644 --- a/application/controllers/main.php +++ b/application/controllers/main.php @@ -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(); } diff --git a/system/controller.php b/system/controller.php index dc51490..02bcbe5 100644 --- a/system/controller.php +++ b/system/controller.php @@ -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'); @@ -37,4 +69,4 @@ public function redirect($loc) } -?> \ No newline at end of file +?>