webCOMAND Apps Tutorial
This tutorial builds on the Content Types, Packages and MVC Apps Tutorials to create a webCOMAND App. webCOMAND Apps are launched from within webCOMAND and can take advantage of a shared environment and webCOMAND Framework.
Create "Presidents" webCOMAND App
To turn our existing package into a simple webCOMAND app:
- Launch the Content Manager (CMS) App.
- In the folder tree on the left, expand and click: / Bases / Presidents / Presidents Demo.
- Click Add Content () in the Collection Bar and select "webCOMAND App" from the drop-down.
- Enter Title "Presidents".
- Enter Identifier "presidents".
- Select Package "Presidents Demo".
- Enter Summary "View and manage United States presidents."
- Upload Icon of United States Flag (same one used for Presidents Content Type).
- Click Approve and Back.
The new Presidents app should now appear last in the main Apps drop-down.
Create "app.php" PHP File
If all the app functionality we want is the webCOMAND headers and a scroll bar, then we are done. To take advantage of the webCOMAND Framework and utilize the built in user interface components though, we need to create a class that extends webcomand_app and defines a launch method, which will be called when the app is launched.
We will add two panels for our user interface for a list of all presidents on the left and a selected president on the right.
- Click Add Content () in the Collection Bar and select "PHP File" from the drop-down.
- Enter Filename "app.php".
- Enter Text:
<?php namespace com_presidentsdemo_www; use com_webcomand\models\WebCOMANDApp; use com_webcomand\components\cpath_view; class 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::PARENTS => ['list'], // display first president initially cpath_view::CPATH => '[:President AND Number=1]' ]); } }
- Click Approve.
Update "index.php" PHP File
Next, we need to update the package router to run the app instead of using the MVC framework.
- Click "PHP File" under "Presidents Demo" in the folder tree on the left.
- Click "index.php" on the right.
- Update the Text to:
<?php namespace com_presidentsdemo_www; $framework = new \com_webcomand\framework(); $framework->require_login(); app::run($framework);
- Click Approve.
Update "Presidents" webCOMAND App
Finally, we need to update the webCOMAND App to specify the webCOMAND App class, so webCOMAND knows what to launch.
- Click "WebCOMAND Apps" under "Presidents Demo" in the folder tree on the left.
- Click "Presidents" on the right.
- Enter the Class Name "app".
- Click Approve.
Conclusion
The Presidents app can now be launched from the Apps drop-down. It uses the webCOMAND Framework to display a mobile-friendly list of presidents that can be clicked to view and edit their details.