I am really new to FuelPHP and PHP / frameworks in general and managed to get everything setup and some controllers running etc. However I am not sure how I can pass a variable I set to the template.php file.
app/views/template.php
Part in question:
<body class="<?php echo $bodyClass; ?>">
app/classes/controller/dashboard.php
class Controller_Dashboard extends Controller_Template
{
/**
* The basic welcome message
*
* @access public
* @return Response
*/
public function action_index()
{
return Response::forge(View::forge('dashboard/index'));
}
/**
* The 404 action for the application.
*
* @access public
* @return Response
*/
public function action_404()
{
return Response::forge(Presenter::forge('dashboard/404'), 404);
}
}
app/classes/view/dashboard/index.php
class View_Dashboard_Index extends ViewModel
{
/**
* Prepare the view data, keeping this in here helps clean up
* the controller.
*
* @return void
*/
public function view()
{
$this->template = $this->request()->param('bodyClass', '');
}
}
I am sure im getting it wrong, well clearly i am as its not working and i get:
Fuel\Core\PhpErrorException [ Notice ]:
Undefined variable: bodyClass
C:/Websites/Annilla/Clients/Four04 Packaging/DEV/NEW/BUILD/backend/app/views/template.php @ line 24
Any ideas?
Also one another thing, is it possible to add partials like loading in menus, headers, footers etc?
Just add another property inside:
$this->template->bodyClass = 'container'; // just assign
And yes, you can add other properties as well.