Welcome!
You are now looking at an Olive Application: here, you can browse the examples and see the source code used to produce each page, watching several Olive resources at work.
To create this page the following resources were used:
- The application object, where the _main() function is being executed in every request.
- The Index Controller class, where the both main() method and the specific _execute_home() method were executed.
- The layout template file that defines the global layout of the page.
- The fixed element template files (header, footer, left, etc...)
- The variable element templates that were chosen in the _execute_home() method: contents.tpl and home.tpl.
Because no request was specified, the application picked the default action index/home from the configuration file. More on that in the Configuration Example.
Click this link (index.php?q=index/home) and watch how this very same page is executed again.
/**
* Olive Demo Application
*/
class olivedemo extends OliveApp
{
/**
* overriden
*
* return false to exit chain of command
*
* @param array $action
*
* @return boolean
*/
protected function _main($action = null)
{
// load header component
$headers = OliveApp::resource('cmp_htmlheader', $this);
// set title
$headers->set_title('Olive Demo Application')
->set_title_delimiter(' | ')
->set_title_concat(TRUE)
// add metas
->add_meta('Content-Language', 'en', TRUE)
->add_meta('Content-Type', 'text/html; charset=ISO-8859-1', TRUE)
->add_meta('author', 'André Torgal')
->add_meta('email', 'info@andretorgal.com')
->add_meta('generator', 'OliveMVC Framework')
->add_meta('robots', 'index,follow')
->add_meta('description', 'Olive is an MVC Framework written in PHP')
->add_meta('keywords', 'olive, php, mvc, framework')
// add icon
->add_icon(OliveUrl::app() . '/media/favicon.ico')
// add stylesheet
->add_stylesheet(OliveApp::url('css') . '/main.css');
// fetch outptut
OliveApp::output()
// set theme
->set_theme('default')
// assign header to output
->assign('headers', $headers);
// do not abort execution
return TRUE;
}
}
The main() method in the application uses two resources:
- It loads and configures a componente called cmp_htmlheaders
- It fetches the output layer to pre-assign some variables/objects to output
/**
* Index controller
*/
class index extends OliveControl
{
/**
* controller main
*
* return false to exit chain of command
*
* @param array $action
*
* @return boolean
*/
protected function _main($action = null)
{
// fetch header
OliveApp::resource('cmp_htmlheader')
// add keywords
->add_keywords('css,javascript,ajax');
// do not abort execution
return TRUE;
}
/**
* home
*/
protected function _execute_home()
{
// fetch header
OliveApp::resource('cmp_htmlheader')
// add title
->add_title('Home');
// fetch output
OliveApp::output()
// set title
->set('title', 'Welcome!')
// set contents template
->set('contents', 'contents')
->set('subcontents', 'home')
// display
->display('index/index');
}
// ... other methods
}
The execution is being delegated to a controller called Index, where the main() method is executed prior to the specific action method _execute_home().
This last method uses the output layer to determine the template being shown and assign the title variable.
Move on to Assign/Set Variables to understand how variables are passed to templates.