php - 如何评估构造函数codeigniter的后值?
问题描述
再会,
我有一个构造函数来检查用户是否登录..
代码:
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
if (!logged_in()) {
redirect('/');
die;
};
}
现在我想添加另一个条件,这样即使没有登录,我仍然可以访问控制器类上的方法,就像我想传递一个密钥进行简单验证一样。
我试图通过$this->input->post('key')
在构造函数中添加来获取表单值。
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$key = $this->input->post('key');
echo $key;
die;
if (!logged_in() OR $key==null) {
redirect('/');
die;
};
}
因此,如果未登录或 $key 为空,则会出现该条件,然后它将重定向到登录页面,但它始终返回空或空。我该如何正确地做到这一点?谢谢您的帮助。
解决方案
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$key = $this->input->post('key');
if(!logged_in() || (logged_in() && $key=='')) {
redirect('/');
die;
}
}
推荐阅读
- python - Python and Calabi Yau Data
- c++ - Ternar operator for 3 cases
- python - Getting 504 Gateway Time-out for Django on Ubuntu
- git - AEM 6.5 中的版本控制元数据更改
- python - AndroRAT Error while executing with python
- git - How to make the parent git folder always point to latest commit whenever there is a new commit in child module(submodule) - Any Alternative?
- javascript - How to get chat id in telegram bot without message from user? Is it even real?
- flutter - type 'double' is not a subtype of type 'int' of 'function result'
- python-3.x - Python: TypeError: 'Label' object is not callable
- python - Pycharm add own function on rightclick menu