This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Difference between revisions of "Controllers"

From Group-Office Groupware and CRM Documentation
Jump to: navigation, search
(Created page with "A controller is a class that contains actions. Actions can be executed by an HTTP call or the Command Line Interface. For example if you would like to create an action for a not...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
A controller is a class that contains actions. Actions can be executed by an HTTP call or the Command Line Interface.
+
A controller is a class that contains actions. Actions can be executed by a HTTP call or the Command Line Interface.
  
 
For example if you would like to create an action for a notes store you would create this controller:
 
For example if you would like to create an action for a notes store you would create this controller:
Line 10: Line 10:
 
}
 
}
 
</pre>
 
</pre>
The character case of the names are very important. The name of the module must start with a capital and all other characters are lowercase. The name after "GO_Notes_Controller_" can be anything but should start with a capital. The filename of the controller must match the case. In this case it would be "modules/notes/controller/NoteController.php"
+
The character case of the names are very important. The name of the module must start with a capital and all other characters are lowercase. The name after "GO_Notes_Controller_" can be anything but should start with a capital. The filename of the controller must match the case. In this case it would be "modules/notes/controller/NoteController.php".
  
 
==Calling actions==
 
==Calling actions==

Latest revision as of 13:30, 17 December 2012

A controller is a class that contains actions. Actions can be executed by a HTTP call or the Command Line Interface.

For example if you would like to create an action for a notes store you would create this controller:

<?php
class GO_Notes_Controller_Note extends GO_Base_Controller_AbstractController{
	protected function actionStore($params){
		return array("success"=>true);
	}
}

The character case of the names are very important. The name of the module must start with a capital and all other characters are lowercase. The name after "GO_Notes_Controller_" can be anything but should start with a capital. The filename of the controller must match the case. In this case it would be "modules/notes/controller/NoteController.php".

Calling actions

Actions are called with a route parameter "r". The route is build up like this:

<MODULE>/<CONTROLLER>/<ACTION>

The <MODULE> part is omitted for core controllers that can be found in the "controller" folder in the root of Group-Office.

The actionStore function in the example code above is now callable with URL:

http://localhost/groupoffice/index.php?r=notes/note/store

All $_REQUEST parameters are passed with the $params variable. Typically actions return an array that will be converted to JSON. A success parameter must be passed. If success = false, then a feedback parameter is required too with the error message.