codeigniter でユーザー認証に Tank_auth を使用しています。ユーザーがログインしているかどうかを確認するには、ユーザー名と ID を取得する場合、コントローラーのすべての機能で次のコードを使用する必要がありますが、これは非常にイライラします。
// If any user is logged in get his/her userid or name
if ($this->tank_auth->is_logged_in()) {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
}
だから、次のfunction __construct()
ようなコードを次のように入れることで生活を楽にすることができるかどうか疑問に思っていましたが、うまくいきません。
動作させる方法を教えてください。
前もって感謝します :)
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth');
if ($this->tank_auth->is_logged_in()) {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
}
}