将变量传递给 FuelPHP 框架中的 template.php 文件
Passing a variable to the template.php file in FuelPHP Framework
我对 FuelPHP 和 PHP / 总体来说是个新手,我设法设置了所有的东西和一些控制器 运行 等等。但是我不确定我该怎么做将我设置的变量传递给 template.php 文件。
app/views/template.php
问题部分:
<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', '');
}
}
我确定我弄错了,很明显我因为它不工作而我得到:
Fuel\Core\PhpErrorException [ Notice ]:
Undefined variable: bodyClass
C:/Websites/Annilla/Clients/Four04 Packaging/DEV/NEW/BUILD/backend/app/views/template.php @ line 24
有什么想法吗?
还有一件事,是否可以添加部分内容,例如在菜单、页眉、页脚等中加载?
在里面再加一个属性就可以了:
$this->template->bodyClass = 'container'; // just assign
是的,您还可以添加其他属性。
我对 FuelPHP 和 PHP / 总体来说是个新手,我设法设置了所有的东西和一些控制器 运行 等等。但是我不确定我该怎么做将我设置的变量传递给 template.php 文件。
app/views/template.php
问题部分:
<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', '');
}
}
我确定我弄错了,很明显我因为它不工作而我得到:
Fuel\Core\PhpErrorException [ Notice ]:
Undefined variable: bodyClass
C:/Websites/Annilla/Clients/Four04 Packaging/DEV/NEW/BUILD/backend/app/views/template.php @ line 24
有什么想法吗?
还有一件事,是否可以添加部分内容,例如在菜单、页眉、页脚等中加载?
在里面再加一个属性就可以了:
$this->template->bodyClass = 'container'; // just assign
是的,您还可以添加其他属性。