私がここで何をしたいか説明しようとしましょう。私はCodeigniter 2.xからKohana 3.2.xにペットプロジェクトを書き直そうとしています。Kohanaセッションの問題
私は、ログインフォームが提出された後、私はセッションデータを設定し、私はController_Site_Templateを拡張コントローラでセッションデータを取得することですが、私(下)サイトテンプレートコントローラ
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();
}
を作成しましたいずれのビューファイルでもセッションデータを取得できません。
私はビューファイルにセッションデータを取得することができています唯一の方法はTemplate_Site_Templateを拡張し、各コントローラにセッションデータを渡すことです:
$this->template->content->set_global('session',$this->template->session->as_array());
が確立し、設定する簡単な方法はありますそれぞれのコントローラーでset_globalを使用するのではなく、すべてのコントローラー、modelc、ビューで使用できるtemplate_controllerのセッション?
私はこれをうまく説明しているのかどうかわかりませんが、私はCodeigniterの$ this-> session-> userdata()の使いやすさに慣れています。どのコントローラー、モデル、ビューでも呼び出すことができる関数です。
私が間違ってやっていることについての入力を前もってありがとうございます。
私はCodeigniterに慣れていて、Kohana 3はMVC全体でちょっと厳しいです。ありがとうございます。 – 12Bo