View system in FMVC

You can associate every handler method in you controller with a view. When you want to return an HTML view, just create a file in the views/ directory using the following structure:

<controller-name>/<action-name>.php

As soon as you are instantiating a PageView object like this:

new PageView($request)

FMVC will automatically search in the passed request object for the information about the called controller action and will then query in views for the corresponding view file as well as for:

  • a CSS file in public/styles/<controller-name>/<action-name>.css
  • a JS file in public/js/<controller-name>/<action-name>.js

If these files are available, it will try top link them together an return the final view as result of the serialize() method.

All views will be rendered inside the views/base.php file. So if you want to create a common design, that should be applied to all of your views, you can edit this file.

If you want to make data available to your view, just pass it along after the request in the constructor. The view will make all variable available in an array called $params.