调用未定义的方法 CI_Input::get_cookie() - Code Igniter
我试图从输入库调用 get_cookie() 方法,但收到此错误。
“致命错误:调用未定义的方法 CI_Input::get_cookie() ”
我已加载 cookie 的帮助程序,并在父函数中使用了调用 set_cookie() 。我不确定这是否应该成为一个问题。
这是创建错误的代码。
class Main extends MY_Controller
{
function __construct()
{
parent::__construct();
//load library
$this->load->helper('cookie');
echo "Welcome controller<br>";
}
function index()
{
//get platform cookie
$_platform = $this->input->get_cookie('platform'); //<-ERROR
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$data['platform'] = $_platform['value'];
$this->load->view('welcome', $data);
}
}
}
I'm trying to make a call to the get_cookie() method from the input library but I am receiving this error.
"Fatal error: Call to undefined method CI_Input::get_cookie() "
I've loaded the helper for cookie and have used the call set_cookie() in the parent function. I'm not sure if this should be an issue.
Here is the code that is creating the error.
class Main extends MY_Controller
{
function __construct()
{
parent::__construct();
//load library
$this->load->helper('cookie');
echo "Welcome controller<br>";
}
function index()
{
//get platform cookie
$_platform = $this->input->get_cookie('platform'); //<-ERROR
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$data['platform'] = $_platform['value'];
$this->load->view('welcome', $data);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您已经加载了 cookie 助手,因此您只需使用函数即可获取 cookie。
如果我没记错的话,通过输入类获取cookie是这样的:
http://codeigniter. com/forums/viewthread/181572/#867911
Since you’ve loaded the cookie helper, you can just fetch the cookie with a function.
And if I recall correctly, getting the cookie via Input class is like this:
http://codeigniter.com/forums/viewthread/181572/#867911