This is an old revision of the document!
Table of Contents
Component class
The component class is a base UI class providing a close binding between PHP and Javascript. The class is intended to be subclassed.
Simple component
In order to create a new, simple component just override the renderContent
-function, such as:
class helloWorld extends Component { public function renderContent() { echo 'Hello world'; } } $mycomponent = new helloWorld(); $mycomponent->render();
Component configuration
To make your component configurable, override the $properties array with some default values. To extend the component from above to make the text and text color configurable, do this:
class textOutput extends Component { protected $properties = array( 'text' => 'Hello world', 'color' => 'black' ); public function renderContent() { echo '<span style="color:'.$this->color.';">'; echo $this->text; echo '</span>'; } } $mycomponent = new textOutput(); $mycomponent->text = 'Platform4PHP is cool'; $mycomponent->color = 'red'; $mycomponent->render();
Note how the configuration properties is easily set and read.
HTML and Javascript bindings
The component will always render in a double div with the following properties:
An outer div with a static class platform_component and an inner div with a class based on the class name of the component, so if the component is named textOutput, the class will be named platform_component_textoutput.
Other classes can also be added for internal handling.
The outer div will have an auto-generated id or you can set the id with the setID
-function.
Example
- index.php
class textOutput extends Component { public $configuration = array( 'text' => 'Hello world', 'color' => 'black' ); public function renderContent() { echo '<span style="color:'.$this->color.';">'; echo $this->text; echo '</span>'; } } $mycomponent = new textOutput(); $mycomponent->text = 'Platform4PHP is cool'; $mycomponent->color = 'red'; $mycomponent->setID('example_output'); $mycomponent->render();
Other javascript functionality
There are some build-in javascript functionality, which can be triggered with events.
event | Effect |
---|---|
disable | Disables the component, by rendering a black square over it. |
enable | Re-enables the component. |
disable_others | Disable every other component except this. |
enable_others | Re-enables every other component except this. |
redraw | Redraws the component by fetching its content from the server |
Prevent disabling
Some components are purely visual and shouldn't be allowed to be disabled. To prevent a component from becoming disabled, set the static $can_disable
variable to false in the php file.