我想将所有这些变量放在一个地方,以便我可以使用模型将它们添加到DB中。 预先谢谢你。
public function web_login()
{
$data['user'] = array();
if ($this->facebook->is_authenticated())
{
$user = $this->facebook->request('get', '/me?fields=id,name,email');
if (!isset($user['error']))
{
$data['user'] = $user; // ***WANNA PASS THIS VARIABLE FROM HERE***
$this->load->view('user/header');
$this->load->view('user/fbpass');
$this->load->view('user/footer');
}
else {
$this->load->view('user/register');
}
}
}
第二种方法________________________________________________
public function getpass(){
$this->load->model('user_model', 'auth');
$this->load->view('user/header');
$this->load->library('form_validation');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passwordagain', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('user/fbpass');
}
else
{
$password=$this->input->post('password');
***//WANNA GET THAT VARIABLE HERE***
}
}
答案 0 :(得分:0)
class ClassName{
public $var;
function one(){
$this->var = 'value';
}
function two(){
return $this->var; // if you call function one then call function two you will get value
}
}
但是如果您需要在不同时间打电话给他们,则可以使用会话
$_SESSION['var'] = 'value';
答案 1 :(得分:0)
class TestClass extends Controller {
function test_mehtod($param) {
//do something
echo $param."<br>";
echo "hi, you are in same controller";
}
function test_mehtod2() {
//do something-else
$this->test_mehtod("param value");
// and we called the other method here!
}
}