webCOMAND

controller::view()

Load and process a view file from the views/ folder.

Prototype

mixed view(string $name, array $data = [], boolean $return = FALSE)

Parameters

  • name - Name of the view, including slash-separated subdirectories within the view folder.  The name does not include the ".php".
  • data - Optional associative array of variables to make available to the view.
  • return - If FALSE (default), echo the view output to the browser.  If TRUE, return the view output as a string.

Return

TRUE is always returned if the return parameter is omitted or FALSE.  Otherwise the output from the view is returned as a string.

Example

// the default controller method
public function web__index() {
    // load contacts to display in the view
    $contacts = $this->repo()->get('FROM Contacts');

    // load and echo the view from views/contact_list.php
    $this->view('contact_list', ['contacts', $contacts]);
}

Related

view::render()