This site uses cookies in order for our service to work better. Learn more I understand

Controller

A controller is called out from router level and that's where we define which controler to call out depending on the path


Path and names of controllers

Controller has to have a name representing structure of an autoloader, that is classes with name "adminMainController", name of the file has to look like this: "adminMainController.class.php". Controllers are in the path or in /app/controller/ or inside of a given plugin that is /app/plugins/OUR_PLUGIN/controller/ Subpaths are also allowed for the controller folder and they are accordingly /do or /ajax. Only from those paths system will download controllers available in our system.


Controller file structure

A controller is coded in object oriented PHP,  that's why it inherits after specified classes, it of course doesn't have to inherit, however we're using a certain standard arising from WinduCORE
Class simpleController Extends htmlController {
	public function index()
	{
		$pagesDB = new pagesDB();
		$this->smarty->assign('pagesDB',$pagesDB);
		$this->pageDisplay('main.tpl');
	}
}
As we can see our simpleController is extended by htmlController, which adds support of smarty and allows displaying of .tpl files. In our simple controller we've created a grip to $pagesDB table and returned it to the template main.tpl in which we can keep on using our table object.
 

Extending controller and setting up paths

It is important to define the folder from which system has to download templates. If we're creating our plugin, this folder has to contain templates in plugin structure. In order to define your own paths you have to extend our controller with a transitional controller. You can do it in the same file but it won't good for easy use if the amount of files grows.

To do so, we create a new controller "simpleMainController" and we extend our base one.
Class simpleController Extends simpleMainController {
	public function index()
	{
		$pagesDB = new pagesDB();
		$this->smarty->assign('pagesDB',$pagesDB);
		$this->pageDisplay('main.tpl');
	}
}


The controller "Main" after which we will extend all the controllers of our plugin
Class simpleMainController Extends htmlController {
	public function __construct(request $request)
	{
		parent::__construct($request);	
		cron::run();
		lang::set('front');
	}
	public function smartyGo()
	{
		parent::smartyGo();
		$this->smarty->template_dir = array_merge(array(__SITE_PATH . '/app/plugins/wp/templates/'),$this->smarty->template_dir);

		$this->smarty->left_delimiter = "{";
		$this->smarty->right_delimiter = "}";
		
		$this->smarty->setCaching(config::get('cache'));
		$this->smarty->setCacheLifetime(config::get('cacheLife'));

		$this->smarty->assign('TEMPLATE_HOME',HOME.'/app/plugins/wp/templates/'.$template);
		$this->smarty->assign('TEMPLATE_PATH',__SITE_PATH . '/app/plugins/wp/templates/');
		
	}	
	public function index(){}
}

When creating a new controller we suggest using an already created one as an example.

Help Center

Do you have a technical problem?