Dotz Framework

Views

All views should reside in the views directory defined in the configs/app.txt file under the ‘viewsDir’ property.

View files can be simple HTML with any PHP data and operations being encapsulated in <?php and ?> script tags.

The dotz setup process adds a few examples for you to be inspired by.


## $dotz Object

The $dotz object is passed along with the following properties:

  • $dotz->url: the full app URL for easy reference in links, etc.
  • $dotz->viewsUrl: the full HTTP URL leading the views directory to refer to asset files, etc.
  • $dotz->configs: carries all the system configs defined in configs/ directory.
  • $dotz->js: JS configs [defined in configs/js.txt] in JSON format to be passed along to JS.

## Accessing Controller’s $packet in the View

In your controller you are encouraged to collect all your objects, arrays and data you wish to pass along to the view in an array named $packet. The various elements should be referenced with well defined keys, which would be extracted to become stand alone variables in the views for easy referencing.

For example…
Suppose you have the following controller method:

class ClassController {
  public function index(){
    $packet = [] // declare the array
    $packet['name'] = 'John Doe';
    $packet['data'] = new EmployeeObject();
    $this->view('someView', $packet);
  }
}

In your someView.php file found in the Views directory, you could access these two variables like so:

//--------someView.php file
<?php
echo $name; // will print out 'John Doe'

// will perform some operation as defined in EmployeeObject::showAddress() method.
$data->showAddress();

This practice too was inspired by CodeIgniter’s handling of views.