Controller

Controller is the main actor in framework lifes. A Controller is simply a class file that is named in a way that can be associated with a URI. If you extract Seme Framework on XAMPP/htdocs/seme/ and then you called http://localhost/seme/blog/, you are accessing the Blog Controller, if the blog.php file is existed on your controller folder. By Default, if you accessing http://localhost/seme/ it will executing home controller which is the default controller for first request in Seme Framework.

The Condition

A Controller can be loaded if URI request has same name with filename of controller and class name of controller. Like example before, if you access blog URI make sure that file blog.php is existed in app/controller/ and the class name is blog with extending Sene_Controller.

What if not found?

By Default Seme Framework has fallback controller named notfound controller which is included in Seme Framework package. You can override the controller, if you wish.

Default Controller

Here is the default source code of controller.

class Home extends Sene_Controller{
	public function __construct(){
		parent::__construct();
	}
	public function index(){
		echo 'Thankyou for using Seme Framewrok';
	}
}
					

Notfound Controller

Here is the default source code of notfound controller.

class Notfound extends Sene_Controller{
	public function __construct(){
		parent::__construct();
	}
	public function index(){
		header("HTTP/1.0 404 Not Found");
		echo '404 Notfound';
	}
}
					

Please make sure your class name are match with filename.

Seme Framework only use lowercase filename, but there is no restriction for class name use capital at first name. You can do CamelCase if you want on class name.

Controller Composition

Like a object oriented lesson, a controller can have properties and methods. First, if you want the class can be identified as a controller, you have to extends Sene_Controller on class declaration. After that, you have to re-executed parent constructor if you want use all benefit from Sene_Controller on your controller (parent::__construct();).

Private Properties and Methods

Seme Framework allow your method in Private or in Protected mode. The Private or Protected mode cant be executed through URI request. Or you can use double underscore (__) means as Private properties or methods.

class Home extends Sene_Controller{
	var $public_var = 'Yi-Ha!';
	var $__underWear = 'My Private Things';
	public function __construct(){
		parent::__construct();
	}
	private function __processFile(){
		return true;
	}
	public function index(){
		echo '404 Notfound';
	}
}
					

Loading the Model

Model is a class contain about communication from framework to database. Model is a bridge for data that can be fetch or push to database from controller. You can load model in constructor if you want executed widely in certain controller. Or you can load inside method of a controller.

class Home extends Sene_Controller{
	public function __construct(){
		parent::__construct();
		$this->load('users_model','alias_of_user_model'); #class scope model
	}
	private function __processFile(){
		return true;
	}
	public function index(){
		$this->load('address_model','alias_of_address_model'); #method scope model
		echo '404 Notfound';
	}
}
					

Loading the Theme

Theme is collection of view file that meets requirement of Seme Framework. Please refer to this section if you want learn more.

class Home extends Sene_Controller{
	public function __construct(){
		parent::__construct();
		$this->setTheme('name_of_theme'); //located at app/view/name_of_theme
	}
}
					

Debug variable

Seme framework has builtin debugging in controller and view scope. The purpose of debugger for debugging variable on controller or view.

class Home extends Sene_Controller{
	public function __construct(){
		parent::__construct();
		$this->setTheme('front');
		$this->load('front/user_model','um');
	}
	public function index(){
		$data = array();
		
		$data['user'] = $this->um->getById($id);
		
		//debugging $data
		$this->debug($data);
		die();
		
		$this->putThemeContent('home/home',$data);
		
		$this->setLayout('col-1',$data);
		$this->render();
	}
}