私のこのブログ投稿では、特に Ion_Auth を使用して、アプリケーション全体 (ビューを含む) が現在のユーザーの情報にアクセスできるようにする方法について詳しく説明しています。
短いバージョン... (特に当面のトピックについて)
MY_Controller.php
これをファイルに追加する
class User_Controller extends CI_Controller {
protected $the_user;
public function __construct() {
parent::__construct();
if($this->ion_auth->logged_in()) {
$data->the_user = $this->ion_auth->get_user();
$this->the_user = $data->the_user;
$this->load->vars($data);
}
else {
redirect('/');
}
}
}
次に、アプリケーションで次のようにコントローラーを作成します
class App_Controller extends User_Controller {
public function __construct() {
parent::__construct();
}
function index() {
//do stuff
}
}
次に、コントローラーだけでなく、すべてのビューにアクセスできるようになり$this->the_user
ます$the_user
$this->load->vars()