View
The View class allows you to load views, assets such as javascript and style sheet files, and specify other various options for view files.
includeJavascript
Assign javascript code or file to be executed or loaded when page is displayed. This is useful if you need to add javascript to your page since you can tell the system to load it from within the controller.
// // the following code will produce this output in the <head> section of the page
// <script type="text/javascript">head.js("https://www.example.com/externals/file.js");</script>
view::includeJavascript('externals/file.js');
// // the following code will produce this output right above the </body> tag of the page
// <script type="text/javascript">head(function(){alert("hey!");});</script>
view::includeJavascript('alert("hey");', 'footer');
includeStylesheet
Assign style sheet file to be included when page is displayed.
// the following code will produce this output in the <head> section of the page
// <link href="https://www.example.com/externals/style.css" rel="stylesheet" type="text/css" />
view::includeStylesheet('externals/style.css');
setTitle
Set page title.
view::setTitle('Welcome to my site'); // set page title displayed above content and <title> tag
view::setTitle('Welcome to my site', false); // set page title displayed above content but don't change <title> tag
setMetaTitle
Set <title> tag.
view::setMetaTitle('Welcome to my site'); // set <title> tag
setMetaDescription
Set description meta tag.
view::setMetaDescription('My site description');
setMetaKeywords
Set keywords meta tag.
view::setMetaKeywords('cool site, great products');
setTrail
Add link to the trail navigation.
view::setTrail('users/manage', 'My profile');
view::setTrail('blogs/manage', 'My blogs');
setAction
Add link to the action navigation (such as “new blog”, “add pictures”, etc).
view::setAction('blogs/edit', 'New blog', array('class' => 'icon-text icon-blogs-new'));
setTab
Add tab link.
view::setTab('users', 'Search', array('class' => 'icon-text icon-users-search'));
view::setTab('users?tab=advanced', 'Advanced search', array('class' => 'icon-text icon-users-search active'));
setError
Set error message.
view::setError('Error message');
setInfo
Set success message.
view::setInfo('Success message');
ajaxError
Return json encoded error for ajax based requests.
view::ajaxError('Error message');
ajaxResponse
Return json encoded output.
view::ajaxResponse('Any data of your choice');
noAccess
Set error message or redirect user to a “no access” page.
view::noAccess(); // redirect user to example.com/site/no_access
view::noAccess('billing/plans'); // redirect user to example.com/billing/plans and display an error message
view::noAccess('billing/plans', 'Custom error'); // redirect user and display custom error message
view::noAccess('billing/plans', false); // redirect user and do not display any errors
view::noAccess(false, 'Custom error'); // display error but do not redirect