【发布时间】:2011-12-24 16:00:04
【问题描述】:
让我试着解释一下我想在这里做什么。我正在尝试将一个宠物项目从 Codeigniter 2.x 重写为 Kohana 3.2.x。
我创建了一个站点模板控制器(如下)
class Controller_Site_Template extends Controller_Template
{
public $template = 'templates/hero';
/**
* The before() method is called before your controller action.
* In our template controller we override this method so that we can
* set up default values. These variables are then available to our
* controllers if they need to be modified.
*/
public function before()
{
parent::before();
if ($this->auto_render)
{
// Initialize empty values
$this->template->title = '';
$this->template->content = '';
$this->template->session = '';
$this->template->styles = array();
$this->template->footer_scripts = array();
$session = Session::instance();
$this->template->session = $session;
}
}
/**
* The after() method is called after your controller action.
* In our template controller we override this method so that we can
* make any last minute modifications to the template before anything
* is rendered.
*/
public function after()
{
if ($this->auto_render)
{
$styles = array(
'assets/css/style.css' => 'screen',);
$footer_scripts = array(
'assets/js/libs/jquery-1.7.1.min.js',
'assets/js/application.js',
);
$this->template->styles = array_merge( $this->template->styles, $styles );
$this->template->footer_scripts = array_merge( $this->template->footer_scripts, $footer_scripts );
}
parent::after();
}
提交登录表单后,我设置了会话数据,并且能够在扩展 Controller_Site_Template 的控制器中检索会话数据,但我无法在任何视图文件中检索会话数据。
我能够在视图文件中获取会话数据的唯一方法是在扩展 Template_Site_Template 的每个控制器中传递会话数据:
$this->template->content->set_global('session',$this->template->session->as_array());
是否有一种简单的方法可以在 template_controller 中建立和设置会话,该会话可用于所有控制器、modelc、视图,而不是在每个单独的控制器上使用 set_global?
我不知道我是否解释得很好,但我已经习惯了 Codeigniter 的 $this->session->userdata();设置后可以在任何控制器、模型和视图中调用的函数。
提前感谢您对我做错的任何意见。
【问题讨论】:
标签: php session kohana kohana-3