View

Views are generated two ways in Brain. First is the standard way we’re used to, like in CodeIgniter. Brain can also store views in the database, which can be handy if you want to search to content using MySQL.

Standard Views

View::load( 
  $view, 
  $view_data = array(), 
  $return = FALSE 
);

DB Views

Adding a DB type view is done through the CLI. This creates a record in the database, and also creates a file that you will work with on the dev environment. When the file gets changed, you’ll simply run and update through the CLI, and the current version of the file is saved in the database record. This is all sort of a proof of concept. If this was to be used in a production environment, further development would be needed.

Add a View

php index.php manual_tests add_view db/test manual_tests/db_view "View from DB" "Testing of a view stored in the database"

This would create the view by calling the add_view method of the manual_tests controller. The file version of the view is saved in the app/views directory, and in this case app/views/db/test.php. The URI string, in this case “manual_tests/db_view”, is the joined URI segments that we want to use to access the page via a browser. The title parameter allows for the database record to hold a title, in case we need to display one in the document head. Last, the desc parameter allows for us to save a short description about the page the view would be displayed on.

Update a View

php index.php manual_tests update_views

Just run the CLI command and the database view records are updated to match the file version.