webCOMAND

component::add_component()

Add a child component to the this component.

Prototype

add_component(mixed $component, array $options = []): array

Parameters

  • component - The component instance to add, or a or the fully qualified class name of a component instance to instantiate.  Common components are:
    • \com_webcomand\components\cpath_view -
  • options - Associative array of general component options like the following, as well as component-specific options (see each component class documentation for their unique options).
    • Container - The user interface container area the component should be added to.  For more information, see ?.
      • 'TopViewContainer'
      • 'LeftViewContainer'
      • 'CenterViewContainer' (default) - The main/center area of the user interface.
      • 'RightViewContainer'
      • 'BottomViewContainer'
    • Identifier - A unique identifier string to assign to this component, so it can be referenced by name from other components.
    • Prepend - If TRUE, add the component to be the first within the container if any other components are already in the container.  Otherwise (default), add the component to the end.

Return

An associative array of "component data".  This same information is automatically converted to JSON and sent to the web browser so that it is available to the component in JavaScript.

Example

<?php
namespace com_presidentsdemo_www;

use com_webcomand\models\WebCOMANDApp;
use com_webcomand\components\cpath_view;

class presidents_app extends WebCOMANDApp {
    public function launch($options = []) {
        // populate LeftViewContainer with all presidents
        $this->add_component('\com_webcomand\components\cpath_view', [
                'Container' => 'LeftViewContainer',
                'Identifier' => 'list',
                cpath_view::CPATH => '[:President]'
        ]);

        // populate CenterViewContainer with first president
        $this->add_component('\com_webcomand\components\cpath_view', [
             'Container' => 'CenterViewContainer',
             'Identifier' => 'form',
             // link this view to the list above with:
             cpath_view::PARENT_IDENTIFIER => ['list'],
             // display first president initially
             cpath_view::CPATH => '[:President AND Number=1]'
        ]);
    }
}