webCOMAND

view::render()

Load and process a view, and echo or return the result as a string.

This method is useful for views that do not match the standard view path or filename conventions, or to load a view outside of the context of a router or controller.  When called from the context of a router or controller, it is generally easier and a better practice to call router::view() or controller::view().

Prototype

static mixed render(string $filename, array $vars = [], boolean $return = FALSE)

Parameters

  • filename - Full path and filename of the view, including the file extension.  If the filename starts with a slash (/), it will be treated as the full path.  Otherwise, it will be treated as a relative path from the file where PHP execution started, which is typically the cMVC router, or webCOMAND (comand.php) if it is used to initially route to the package.
  • vars - Optional associative array of variables to make available in the view, where the array keys are the variable names and the values are the variable values, which may be any type.
  • 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

$results = $repo->get('FROM Contacts');
\io_comand_mvc\view::render('contacts.php', ['contacts'=>$results]);

Related

controller::view()