我的控制器功能为:
public function verify()
{
$token= $this->uri->segment(3);
$email_verification=$this->load->site_model->verifyEmailAddress($token);
if ($email_verification=== FALSE)
{
redirect('site/index');
}
else
{
$type=$this->load->site_model->select1($token);
//print_r($type);
if($type['user_type']=="Employer"){
redirect('site/emp');
}
else{
redirect('site/seek');
}
}
}
我的模特是:
<?php
class Site_model extends CI_Model
{
public function __construct()
{
parent:: __construct();
$this->load->database();
}
public function insert($token)
{
$data = array(
'name'=>$this->input->post('name'),
'email'=>$this->input->post('email'),
'phone'=>$this->input->post('phone'),
'user_type'=>$this->input->post('utype'),
'token'=>$token,
);
$this->db->insert('tbl_user',$data);
$email=$this->input->post('email');
$name=$this->input->post('name');
$html ="http://localhost/jobs/hmvc/index.php/site/verify/".$token;
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someone@gmail.com',
'smtp_pass' => 'something',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email',$config);
$this->email->From("someone@gmail.com");
$this->email->to($email);
$this->email->subject('test');
$this->email->message('<b>Hi '.$name.' </b><p>Welcome! You’re almost done.!Click the link to confirm your email address..</p>'.$html);
//$this->email->send();
if($this->email->send()) {
echo '<script>alert("Email sent successfully")</script>';
} else {
$this->email->print_debugger();
}
}
public function verifyEmailAddress($token)
{
$data=array('email_verification'=>1);
$this->db->where('token',$token);
$this->db->update('tbl_user',$data);
return true;
}
public function select1($token) {
$this->db->select('user_type');
$this->db->from('tbl_user');
$this->db->where('token',$token);
return $this->db->get()->row();
}
?>
当运行代码的em显示为致命错误的错误:不能在第89行的C:\ xampp \ htdocs \ jobs \ hmvc \ application \ modules \ site \ controllers \ site.php中使用stdClass类型的对象< / p>
我该如何解决这个问题? codeigniter中的这个错误是什么意思?
答案 0 :(得分:0)
<?php
public function insert($token)
{
$data = array(
'name'=>$this->input->post('name'),
'email'=>$this->input->post('email'),
'phone'=>$this->input->post('phone'),
'user_type'=>$this->input->post('utype'),
'token'=>$token,
);
$this->db->insert('tbl_user',$data);
$ret =$this->db->insert_id();
$email=$this->input->post('email');
$name=$this->input->post('name');
$html ="http://localhost/jobs/hmvc/index.php/site/verify/".$token;
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someone@gmail.com',
'smtp_pass' => 'something',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email',$config);
$this->email->From("someone@gmail.com");
$this->email->to($email);
$this->email->subject('test');
$this->email->message('<b>Hi '.$name.' </b><p>Welcome! You’re almost done.!Click the link to confirm your email address..</p>'.$html);
//$this->email->send();
if($this->email->send()) {
echo '<script>alert("Email sent successfully")</script>';
} else {
$this->email->print_debugger();
}
if($ret){
// $this->db->where('id', $ret);
// $query=$this->db->get('tbl_user');
// $result = $query->result_array();
// return $result;
return $this->select1($token);
}
}
public function select1($token) {
$this->db->select('user_type'); $this->db->from('tbl_user');
$this->db->where('token',$token);
return $this->db->get()->row();
}
您可以尝试使用此功能进行插入。请在同一型号中使用此功能。
答案 1 :(得分:0)
在控制器中
public function verify()
{
$token= $this->uri->segment(3);
$email_verification = $this->load->site_model->verifyEmailAddress($token);
if ($email_verification != 1)
{
redirect('site/index');
}
else
{
$type=$this->load->site_model->select1($token);
//print_r($type);
if($type['user_type']=="Employer"){
redirect('site/emp');
}
else{
redirect('site/seek');
}
}
}
在模型中
public function verifyEmailAddress($token)
{
$data=array('email_verification'=>1);
$this->db->where('token',$token);
$this->db->update('tbl_user',$data);
return 1;
}
public function select1($token)
{
$query = $this->db->query("SELECT user_type FROM tbl_user WHERE token = '$token' ");
$result = $query->result_array();
return $result;
}
答案 2 :(得分:0)
我知道我可能会迟到1年,但所有答案都只是代码,而stackoverflow答案应该更多地是解决问题的指导。
您收到此错误的原因是因为模型中的 Select1 函数返回了一个对象: $.ajax({
url: "index2.php?id=upload",
type: "POST",
data: new FormData($("#form")[0]),
contentType: false,
cache: false,
processData:false,
dateType:"json",
success: function(data)
{
console.log('names:'+JSON.stringify(data));
$.each(data, function(i,v)
{
console.log('name:'+v.name);
}
},
在控制器中,您将返回的值保存为
return $this->db->get()->row();
然后,你有if-else语句,条件是:
$type=$this->load->site_model->select1($token);
您正在尝试使用$type['user_type']=="Employer";
的键(索引)获取变量$type
,这是一个数组,而您的模型返回该对象。
因此,解决方案是在控制器中从"user_type"
更改为$type['user_type']=="Employer"
,实际上是指对象的名为“user_type”的属性。