新手问题,我的类方法中有变量,我是否必须将它们设为类变量,以便我可以使用 $this 访问它们?如果不是,请解释我何时使用或制作类变量?
private function is_valid_cookie()
{
$securedtoken = $this->input->cookie('securedtoken');
// Checks if the cookie is set
if (!empty($securedtoken)) {
// Checks if the cookie is in the database
$s = $this->db->escape($securedtoken);
$query = $this->db->query("SELECT cookie_variable FROM jb_login_cookies WHERE cookie_variable=$s");
if ($query->num_rows() != 0) {
// Now let us decrypt the cookie variables
$decoded = unserialize($this->encrypt->decode($securedtoken));
$this->login($decoded['username'], $decoded['password']);
return true;
} else {
return false;
}
} else {
return false;
}
}
正如你们所看到的,我有变量 $securedtoken 和 $decoded = array(),我无法决定是否必须将它们设为类变量并使用 $this 访问它们