Projects View

Next up, let's develop out the Disaster Relief->Projects menu. This one we will do manually, not because it's the most effective method, but to give you an understanding of what's possible with Apex and how to develop manually. Run the following create view CLI command:

apex create view disaster admin/disaster/projects

This will create two files located at:

  • /views/html/admin/disaster/projects.html
  • /views/php/admin/disaster/projects.php

Every view within Apex has both, a .html file for the design and a .php file for the functionality which acts as a link between the views and actual back-end application. You may view details on the PHP classes via the Creating Views and PHP Class Per-View pages of the documentation.

/views/html/admin/disaster/projects.html

Open the file at /views/html/admin/disaster/projects.html and replace it with the following contents:


<h1>Projects</h1> <s:form> <s:tab_control> <s:tab_page name="Create Project"> <h3>Create New Project</h3> <s:form_table> <s:ft_select name="location_id" label="Location" required="1"> ~location_options~ </s:ft_select> <s:ft_select name="status" value="in_progress" required="1" data_source="hash.disaster.project_status"> <s:ft_textbox name="title"> <s:ft_textarea name="description"> <s:ft_submit value="create" label="Create New Project"> </s:form_table> </s:tab_page> </s:tab_control>

/views/php/admin/disaster/projects.php

Next, open the /views/php/admin/disaster/projects.php file andreplace it with the following contents:

<?php
declare(strict_types = 1);

namespace Views\admin\disaster; 

use Apex\Svc\{View, App};
use App\Disaster\Controllers\ProjectController;

/**
 * Render the template.  All methods below are optional, may be 
 * removed as desired, and all methods support method based dependency injection.
 */
class projects
{

    /**
     * Render
     */
    public function render(View $view, ProjectController $proj_controller):void
    {

        // Location options
        $options = $proj_controller->createLocationOptions();

        // Template variables
        $view->assign('location_options', $options);
    }

    /**
     * POST
     */
    public function post(View $view, App $app, ProjectController $proj_controller):void
    {

        // Create
        if ($app->getAction() == 'create') {

            if ($proj = $proj_controller->create()) {
                $view->addCallout("Successfully created new project, " . $app->post('title'));
            }
        }

    }


}

The above will generate all location options for the select list as the HTML page defines. That method does not currently exist, but will be developed out on the next page.