【发布时间】:2019-07-09 04:24:22
【问题描述】:
尝试修复我在某些代码中遇到的错误。
我尝试编辑模型,但没有任何效果。还编辑了控制器,更新了数据库,并确保某些文件夹位于父目录中。试图弄清楚如何解决这个错误。如果有人可以提供帮助,将不胜感激!!!
查看:
<?php
if(file_exists('/assets/images/'.$user_data[0]->profile_pic) && isset($user_data[0]->profile_pic)){
$profile_pic = $user_data[0]->profile_pic;
}else{
$profile_pic = 'user.png';}?>
<center> <img class="thumb-image setpropileam" src="<?php echo base_url();?>/assets/images/<?php echo isset($profile_pic)?$profile_pic:'user.png';?>" alt="User profile picture"></center>
型号:
<?php
class User_model extends CI_Model {
function __construct(){
parent::__construct();
$this->user_id =isset($this->session->get_userdata()['user_details'][0]->id)?$this->session->get_userdata()['user_details'][0]->users_id:'1';
}
/**
* This function is used authenticate user at login
*/
function auth_user() {
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->db->where("is_deleted='0' AND (name='$email' OR email='$email')");
$result = $this->db->get('users')->result();
if(!empty($result)){
if (password_verify($password, $result[0]->password)) {
if($result[0]->status != 'active') {
return 'not_varified';
}
return $result;
}
else {
return false;
}
} else {
return false;
}
}
/**
* This function is used to delete user
* @param: $id - id of user table
*/
function delete($id='') {
$this->db->where('users_id', $id);
$this->db->delete('users');
}
/**
* This function is used to load view of reset password and varify user too
*/
function mail_varify() {
$ucode = $this->input->get('code');
$this->db->select('email as e_mail');
$this->db->from('users');
$this->db->where('var_key',$ucode);
$query = $this->db->get('cultured_codeignite');
$result = $query->row();
if(!empty($result->e_mail)){
return $result->e_mail;
}else{
return false;
}
}
/**
* This function is used Reset password
*/
function ResetPpassword(){
$email = $this->input->post('email');
if($this->input->post('password_confirmation') == $this->input->post('password')){
$npass = password_hash($this->input->post('password'), PASSWORD_DEFAULT);
$data['password'] = $npass;
$data['var_key'] = '';
return $this->db->update('users',$data, "email = '$email'");
}
}
/**
* This function is used to select data form table
*/
function get_data_by($tableName='users', $value='', $colum='',$condition='') {
if((!empty($value)) && (!empty($colum))) {
$this->db->where($colum, $value);
}
$this->db->select('*');
$this->db->from($tableName);
$query = $this->db->get('cultured_codeignite');
return $query->result();
}
/**
* This function is used to check user is alredy exist or not
*/
function check_exists($table='', $colom='',$colomValue=''){
$this->db->where($colom, $colomValue);
$res = $this->db->get($table)->row();
if(!empty($res)){ return false;} else{ return true;}
}
/**
* This function is used to get users detail
*/
function get_users($userID = '') {
$this->db->where('is_deleted', '0');
if(isset($userID) && $userID !='') {
$this->db->where('users_id', $userID);
} else if($this->session->userdata('user_details')[0]->user_type == 'admin') {
$this->db->where('user_type', 'admin');
} else {
$this->db->where('users.users_id !=', '1');
}
$result = $this->db->get('users')->result();
return $result;
}
/**
* This function is used to get email template
*/
function get_template($code){
$this->db->where('code', $code);
return $this->db->get('templates')->row();
}
/**
* This function is used to Insert record in table
*/
public function insertRow($table, $data){
$this->db->insert($table, $data);
return $this->db->insert_id();
}
/**
* This function is used to Update record in table
*/
public function updateRow($table, $col, $colVal, $data) {
$this->db->where($col,$colVal);
$this->db->update($table,$data);
return true;
}
}
这是错误:
严重性:通知
消息:未定义变量:user_data
文件名:views/profile.php
行号:475
回溯:
文件:/home4/cultured/public_html/application/views/profile.php 行: 475 函数:_error_handler
文件:/home4/cultured/public_html/application/controllers/Login.php 行:47 功能:查看
文件:/home4/cultured/public_html/index.php 行:315 功能: require_once 遇到 PHP 错误
严重性:通知
消息:试图获取非对象的属性
文件名:views/profile.php
行号:475
【问题讨论】:
-
你能把你的控制器代码(功能)吗
-
您在代码中哪里设置了这个
$user_data变量? -
大家好!!我试图添加控制器,但它太长了,不适合:(
标签: php codeigniter