• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to get property of non-object error

#1
Hello all!

I got this error and need help fixing:

Severity: Notice

Message: Trying to get property of non-object
Filename: views/profile.php
Line Number: 475



Tried to var dump but didnt know where to place it. I feel its an issue with connecting to DB.

View issue line:
 <?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

Controller:
Code:
[b]<?php
[/b]
[b]defined('BASEPATH') OR exit('No direct script access allowed ');[/b]
[b]class User extends CI_Controller {[/b]

[b]    function __construct() {[/b]
[b]        parent::__construct();[/b]
[b]         $this->load->helper(array('form', 'url','sessions')); [/b]
[b]        $this->load->model('User_model');[/b]
[b]        $this->user_id = isset($this->session->get_userdata()['user_details'][0]->id)?$this->session->get_userdata()['user_details'][0]->users_id:'1';[/b]
[b]    [/b]
[b]    }[/b]

[b]    /**[/b]
[b]      * This function is redirect to users profile page[/b]
[b]      * @return Void[/b]
[b]      */[/b]
[b]    public function index() {[/b]
[b]        if(is_login()){[/b]
[b]            redirect( base_url().'dashboard', 'refresh');[/b]
[b]        } [/b]
[b]    }[/b]

[b]    /**[/b]
[b]      * This function is used to load login view page[/b]
[b]      * @return Void[/b]
[b]      */[/b]
[b]    public function login(){[/b]
[b]        if(isset($_SESSION['user_details'])){[/b]
[b]            redirect( base_url().'dashboard', 'refresh');[/b]
[b]        }   [/b]
[b]        $this->load->view('script');[/b]
[b]        $this->load->view('login'); [/b]
[b]    }[/b]

[b]    /**[/b]
[b]      * This function is used to logout user[/b]
[b]      * @return Void[/b]
[b]      */[/b]
[b]    public function logout(){[/b]
[b]        is_login();[/b]
[b]        $this->session->unset_userdata('user_details');               [/b]
[b]        redirect( base_url().'login', 'refresh');[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to registr user[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function registration(){[/b]
[b]        if(isset($_SESSION['user_details'])){[/b]
[b]            redirect( base_url().'dashboard', 'refresh');[/b]
[b]        }[/b]
[b]        //Check if admin allow to registration for user[/b]
[b]        if(setting_all('register_allowed')==1){[/b]
[b]            if($this->input->post()) {[/b]
[b]                $this->add_edit();[/b]
[b]                $this->session->set_flashdata('messagePr', 'Successfully Registered..');[/b]
[b]            } else {[/b]
[b]                $this->load->view('include/script');[/b]
[b]                $this->load->view('register');[/b]
[b]            }[/b]
[b]        }[/b]
[b]        else {[/b]
[b]            $this->session->set_flashdata('messagePr', 'Registration Not allowed..');[/b]
[b]            redirect( base_url().'user/login', 'refresh');[/b]
[b]        }[/b]
[b]    }[/b]
[b]    [/b]
[b]    /**[/b]
[b]     * This function is used for user authentication ( Working in login process )[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function auth_user($page =''){ [/b]
[b]        $return = $this->User_model->auth_user();[/b]
[b]        if(empty($return)) { [/b]
[b]            $this->session->set_flashdata('messagePr', 'Invalid details');    [/b]
[b]            redirect( base_url().'login', 'refresh');  [/b]
[b]        } else { [/b]
[b]            if($return == 'not_varified') {[/b]
[b]                $this->session->set_flashdata('messagePr', 'This accout is not varified. Please contact to your admin..');[/b]
[b]                redirect( base_url().'login', 'refresh');[/b]
[b]            } else {[/b]
[b]                $this->session->set_userdata('user_details',$return);[/b]
[b]            }[/b]
[b]            redirect( base_url().'dashboard', 'refresh');[/b]
[b]        }[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used send mail in forget password[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function forgetpassword(){[/b]
[b]        $page['title'] = 'Forgot Password';[/b]
[b]        if($this->input->post()){[/b]
[b]            $setting = settings();[/b]
[b]            $res = $this->User_model->get_data_by('users', $this->input->post('email'), 'email',1);[/b]
[b]            if(isset($res[0]->users_id) && $res[0]->users_id != '') { [/b]
[b]                $var_key = $this->getVarificationCode(); [/b]
[b]                $this->User_model->updateRow('users', 'users_id', $res[0]->users_id, array('var_key' => $var_key));[/b]
[b]                $sub = "Reset password";[/b]
[b]                $email = $this->input->post('email');      [/b]
[b]                $data = array([/b]
[b]                    'user_name' => $res[0]->name,[/b]
[b]                    'action_url' =>base_url(),[/b]
[b]                    'sender_name' => $setting['company_name'],[/b]
[b]                    'website_name' => $setting['website'],[/b]
[b]                    'varification_link' => base_url().'user/mail_varify?code='.$var_key,[/b]
[b]                    'url_link' => base_url().'user/mail_varify?code='.$var_key,[/b]
[b]                    );[/b]
[b]                $body = $this->User_model->get_template('forgot_password');[/b]
[b]                $body = $body->html;[/b]
[b]                foreach ($data as $key => $value) {[/b]
[b]                    $body = str_replace('{var_'.$key.'}', $value, $body);[/b]
[b]                }[/b]
[b]                if($setting['mail_setting'] == 'php_mailer') {[/b]
[b]                    $this->load->library("send_mail");         [/b]
[b]                    $emm = $this->send_mail->email($sub, $body, $email, $setting);[/b]
[b]                } else {[/b]
[b]                    // content-type is required when sending HTML email[/b]
[b]                    $headers = "MIME-Version: 1.0" . "\r\n";[/b]
[b]                    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";[/b]
[b]                    $headers .= 'From: '.$setting['EMAIL'] . "\r\n";[/b]
[b]                    $emm = mail($email,$sub,$body,$headers);[/b]
[b]                }[/b]
[b]                if($emm) {[/b]
[b]                    $this->session->set_flashdata('messagePr', 'To reset your password, link has been sent to your email');[/b]
[b]                    redirect( base_url().'login','refresh');[/b]
[b]                }[/b]
[b]            } else {    [/b]
[b]                $this->session->set_flashdata('forgotpassword', 'This account does not exist');//die;[/b]
[b]                redirect( base_url()."forgetpassword");[/b]
[b]            }[/b]
[b]        } else {[/b]
[b]            $this->load->view('include/script');[/b]
[b]            $this->load->view('forget_password');[/b]
[b]        }[/b]
[b]    }[/b]

[b]    /**[/b]
[b]      * This function is used to load view of reset password and varify user too [/b]
[b]      * @return : void[/b]
[b]      */[/b]
[b]    public function mail_varify(){[/b]
[b]          $return = $this->User_model->mail_varify();         [/b]
[b]          $this->load->view('include/script');[/b]
[b]          if($return){          [/b]
[b]            $data['email'] = $return;[/b]
[b]            $this->load->view('set_password', $data);        [/b]
[b]          } else { [/b]
[b]              $data['email'] = 'allredyUsed';[/b]
[b]            $this->load->view('set_password', $data);[/b]
[b]        } [/b]
[b]    }[/b]
[b]    [/b]
[b]    /**[/b]
[b]      * This function is used to reset password in forget password process[/b]
[b]      * @return : void[/b]
[b]      */[/b]
[b]    public function reset_password(){[/b]
[b]        $return = $this->User_model->ResetPpassword();[/b]
[b]        if($return){[/b]
[b]            $this->session->set_flashdata('messagePr', 'Password Changed Successfully..');[/b]
[b]            redirect( base_url().'login', 'refresh');[/b]
[b]        } else {[/b]
[b]            $this->session->set_flashdata('messagePr', 'Unable to update password');[/b]
[b]            redirect( base_url().'login', 'refresh');[/b]
[b]        }[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is generate hash code for random string[/b]
[b]     * @return string[/b]
[b]     */[/b]
[b]    public function getVarificationCode(){        [/b]
[b]        $pw = $this->randomString();   [/b]
[b]        return $varificat_key = password_hash($pw, PASSWORD_DEFAULT); [/b]
[b]    }[/b]

[b]    [/b]

[b]    /**[/b]
[b]     * This function is used for show users list[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function userTable(){[/b]
[b]        is_login();[/b]
[b]        if(CheckPermission("users", "own_read")){[/b]
[b]            $this->load->view('include/header');[/b]
[b]            $this->load->view('user_table');                [/b]
[b]            $this->load->view('include/footer');            [/b]
[b]        } else {[/b]
[b]            $this->session->set_flashdata('messagePr', 'You don\'t have permission to access.');[/b]
[b]            redirect( base_url().'dashboard', 'refresh');[/b]
[b]        }[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to create datatable in users list page[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function dataTable (){[/b]
[b]        is_login();[/b]
[b]        $table = 'users';[/b]
[b]        $primaryKey = 'users_id';[/b]
[b]        $columns = array([/b]
[b]           array( 'db' => 'users_id', 'dt' => 0 ),array( 'db' => 'status', 'dt' => 1 ),[/b]
[b]                    array( 'db' => 'name', 'dt' => 2 ),[/b]
[b]                    array( 'db' => 'email', 'dt' => 3 ),[/b]
[b]                    array( 'db' => 'users_id', 'dt' => 4 )[/b]
[b]        );[/b]

[b]        $sql_details = array([/b]
[b]            'user' => $this->db->username,[/b]
[b]            'pass' => $this->db->password,[/b]
[b]            'db'   => $this->db->database,[/b]
[b]            'host' => $this->db->hostname[/b]
[b]        );[/b]
[b]        $where = array("user_type != 'admin'");[/b]
[b]        $output_arr = SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, $where);[/b]
[b]        foreach ($output_arr['data'] as $key => $value) {[/b]
[b]            $id = $output_arr['data'][$key][count($output_arr['data'][$key])  - 1];[/b]
[b]            $output_arr['data'][$key][count($output_arr['data'][$key])  - 1] = '';[/b]
[b]            if(CheckPermission($table, "all_update")){[/b]
[b]            $output_arr['data'][$key][count($output_arr['data'][$key])  - 1] .= '<a id="btnEditRow" class="modalButtonUser mClass"  href="javascript:;" type="button" data-src="'.$id.'" title="Edit"><i class="fa fa-pencil" data-id=""></i></a>';[/b]
[b]            }else if(CheckPermission($table, "own_update") && (CheckPermission($table, "all_update")!=true)){[/b]
[b]                $user_id =getRowByTableColomId($table,$id,'users_id','user_id');[/b]
[b]                if($user_id==$this->user_id){[/b]
[b]            $output_arr['data'][$key][count($output_arr['data'][$key])  - 1] .= '<a id="btnEditRow" class="modalButtonUser mClass"  href="javascript:;" type="button" data-src="'.$id.'" title="Edit"><i class="fa fa-pencil" data-id=""></i></a>';[/b]
[b]                }[/b]
[b]            }[/b]
[b]            [/b]
[b]            if(CheckPermission($table, "all_delete")){[/b]
[b]            $output_arr['data'][$key][count($output_arr['data'][$key])  - 1] .= '<a style="cursor:pointer;" data-toggle="modal" class="mClass" onclick="setId('.$id.', \'user\')" data-target="#cnfrm_delete" title="delete"><i class="fa fa-trash-o" ></i></a>';}[/b]
[b]            else if(CheckPermission($table, "own_delete") && (CheckPermission($table, "all_delete")!=true)){[/b]
[b]                $user_id =getRowByTableColomId($table,$id,'users_id','user_id');[/b]
[b]                if($user_id==$this->user_id){[/b]
[b]            $output_arr['data'][$key][count($output_arr['data'][$key])  - 1] .= '<a style="cursor:pointer;" data-toggle="modal" class="mClass" onclick="setId('.$id.', \'user\')" data-target="#cnfrm_delete" title="delete"><i class="fa fa-trash-o" ></i></a>';[/b]
[b]                }[/b]
[b]            }[/b]
[b]            $output_arr['data'][$key][0] = '<input type="checkbox" name="selData" value="'.$output_arr['data'][$key][0].'">';[/b]
[b]        }[/b]
[b]        echo json_encode($output_arr);[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is Showing users profile[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function profile($id='') {   [/b]
[b]        is_login();[/b]
[b]        if(!isset($id) || $id == '') {[/b]
[b]            $id = $this->session->userdata ('user_details')[0]->{'users_id'};[/b]
[b]        }[/b]
[b]        $data['user_data'] = $this->User_model->get_users($id);[/b]
[b]        $this->load->view('include/header'); [/b]
[b]        $this->load->view('profile', $data);[/b]
[b]        $this->load->view('include/footer');[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to show popup of user to add and update[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function get_modal() {[/b]
[b]        is_login();[/b]
[b]        if($this->input->post('id')){[/b]
[b]            $data['userData'] = getDataByid('users',$this->input->post('id'),'users_id'); [/b]
[b]            echo $this->load->view('add_user', $data, true);[/b]
[b]        } else {[/b]
[b]            echo $this->load->view('add_user', '', true);[/b]
[b]        }[/b]
[b]        exit;[/b]
[b]    }[/b]

[b]    [/b]
[b]    /**[/b]
[b]     * This function is used to upload file[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    function upload() {[/b]
[b]        foreach($_FILES as $name => $fileInfo)[/b]
[b]        {[/b]
[b]            $filename=$_FILES[$name]['name'];[/b]
[b]            $tmpname=$_FILES[$name]['tmp_name'];[/b]
[b]            $exp=explode('.', $filename);[/b]
[b]            $ext=end($exp);[/b]
[b]            $newname=  $exp[0].'_'.time().".".$ext; [/b]
[b]            $config['upload_path'] = 'assets/images/';[/b]
[b]            $config['upload_url'] =  base_url().'assets/images/';[/b]
[b]            $config['allowed_types'] = "gif|jpg|jpeg|png|iso|dmg|zip|rar|doc|docx|xls|xlsx|ppt|pptx|csv|ods|odt|odp|pdf|rtf|sxc|sxi|txt|exe|avi|mpeg|mp3|mp4|3gp";[/b]
[b]            $config['max_size'] = '2000000'; [/b]
[b]            $config['file_name'] = $newname;[/b]
[b]            $this->load->library('upload', $config);[/b]
[b]            move_uploaded_file($tmpname,"assets/images/".$newname);[/b]
[b]            return $newname;[/b]
[b]        }[/b]
[b]    }[/b]
[b]  [/b]
[b]    /**[/b]
[b]     * This function is used to add and update users[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function add_edit($id='') {   [/b]
[b]        $data = $this->input->post();[/b]
[b]        $profile_pic = 'user.png';[/b]
[b]        if($this->input->post('users_id')) {[/b]
[b]            $id = $this->input->post('users_id');[/b]
[b]        }[/b]
[b]        if(isset($this->session->userdata ('user_details')[0]->users_id)) {[/b]
[b]            if($this->input->post('users_id') == $this->session->userdata ('user_details')[0]->users_id){[/b]
[b]                $redirect = 'profile';[/b]
[b]            } else {[/b]
[b]                $redirect = 'userTable';[/b]
[b]            }[/b]
[b]        } else {[/b]
[b]            $redirect = 'login';[/b]
[b]        }[/b]
[b]        if($this->input->post('fileOld')) {  [/b]
[b]            $newname = $this->input->post('fileOld');[/b]
[b]            $profile_pic =$newname;[/b]
[b]        } else {[/b]
[b]            $data[$name]='';[/b]
[b]            $profile_pic ='user.png';[/b]
[b]        }[/b]
[b]        foreach($_FILES as $name => $fileInfo)[/b]
[b]        { [/b]
[b]             if(!empty($_FILES[$name]['name'])){[/b]
[b]                $newname=$this->upload(); [/b]
[b]                $data[$name]=$newname;[/b]
[b]                $profile_pic =$newname;[/b]
[b]             } else {  [/b]
[b]                if($this->input->post('fileOld')) {  [/b]
[b]                    $newname = $this->input->post('fileOld');[/b]
[b]                    $data[$name]=$newname;[/b]
[b]                    $profile_pic =$newname;[/b]
[b]                } else {[/b]
[b]                    $data[$name]='';[/b]
[b]                    $profile_pic ='user.png';[/b]
[b]                } [/b]
[b]            } [/b]
[b]        }[/b]
[b]        if($id != '') {[/b]
[b]            $data = $this->input->post();[/b]
[b]            if($this->input->post('status') != '') {[/b]
[b]                $data['status'] = $this->input->post('status');[/b]
[b]            }[/b]
[b]            if($this->input->post('users_id') == 1) { [/b]
[b]            $data['user_type'] = 'admin';[/b]
[b]            }[/b]
[b]            if($this->input->post('password') != '') {[/b]
[b]                if($this->input->post('currentpassword') != '') {[/b]
[b]                    $old_row = getDataByid('users', $this->input->post('users_id'), 'users_id');[/b]
[b]                    if(password_verify($this->input->post('currentpassword'), $old_row->password)){[/b]
[b]                        if($this->input->post('password') == $this->input->post('confirmPassword')){[/b]
[b]                            $password = password_hash($this->input->post('password'), PASSWORD_DEFAULT);[/b]
[b]                            $data['password']= $password;     [/b]
[b]                        } else {[/b]
[b]                            $this->session->set_flashdata('messagePr', 'Password and confirm password should be same...');[/b]
[b]                            redirect( base_url().'user/'.$redirect, 'refresh');[/b]
[b]                        }[/b]
[b]                    } else {[/b]
[b]                        $this->session->set_flashdata('messagePr', 'Enter Valid Current Password...');[/b]
[b]                        redirect( base_url().'user/'.$redirect, 'refresh');[/b]
[b]                    }[/b]
[b]                } else {[/b]
[b]                    $this->session->set_flashdata('messagePr', 'Current password is required');[/b]
[b]                    redirect( base_url().'user/'.$redirect, 'refresh');[/b]
[b]                }[/b]
[b]            }[/b]
[b]            $id = $this->input->post('users_id');[/b]
[b]            unset($data['fileOld']);[/b]
[b]            unset($data['currentpassword']);[/b]
[b]            unset($data['confirmPassword']);[/b]
[b]            unset($data['users_id']);[/b]
[b]            unset($data['user_type']);[/b]
[b]            if(isset($data['edit'])){[/b]
[b]                unset($data['edit']);[/b]
[b]            }[/b]
[b]            if($data['password'] == ''){[/b]
[b]                unset($data['password']);[/b]
[b]            }[/b]
[b]            $data['profile_pic'] = $profile_pic;[/b]
[b]            $this->User_model->updateRow('users', 'users_id', $id, $data);[/b]
[b]            $this->session->set_flashdata('messagePr', 'Your data updated Successfully..');[/b]
[b]            redirect( base_url().'user/'.$redirect, 'refresh');[/b]
[b]        } else { [/b]
[b]            if($this->input->post('user_type') != 'admin') {[/b]
[b]                $data = $this->input->post();[/b]
[b]                $password = password_hash($this->input->post('password'), PASSWORD_DEFAULT);[/b]
[b]                $checkValue = $this->User_model->check_exists('users','email',$this->input->post('email'));[/b]
[b]                if($checkValue==false)  {  [/b]
[b]                    $this->session->set_flashdata('messagePr', 'This Email Already Registered with us..');[/b]
[b]                    redirect( base_url().'user/userTable', 'refresh');[/b]
[b]                }[/b]
[b]                $checkValue1 = $this->User_model->check_exists('users','name',$this->input->post('name'));[/b]
[b]                if($checkValue1==false) {  [/b]
[b]                    $this->session->set_flashdata('messagePr', 'Username Already Registered with us..');[/b]
[b]                    redirect( base_url().'user/userTable', 'refresh');[/b]
[b]                }[/b]
[b]                $data['status'] = 'active';[/b]
[b]                if(setting_all('admin_approval') == 1) {[/b]
[b]                    $data['status'] = 'deleted';[/b]
[b]                }[/b]
[b]                [/b]
[b]                if($this->input->post('status') != '') {[/b]
[b]                    $data['status'] = $this->input->post('status');[/b]
[b]                }[/b]
[b]                //$data['token'] = $this->generate_token();[/b]
[b]                $data['user_id'] = $this->user_id;[/b]
[b]                $data['password'] = $password;[/b]
[b]                $data['profile_pic'] = $profile_pic;[/b]
[b]                $data['is_deleted'] = 0;[/b]
[b]                if(isset($data['password_confirmation'])){[/b]
[b]                    unset($data['password_confirmation']);    [/b]
[b]                }[/b]
[b]                if(isset($data['call_from'])){[/b]
[b]                    unset($data['call_from']);    [/b]
[b]                }[/b]
[b]                unset($data['submit']);[/b]
[b]                $this->User_model->insertRow('users', $data);[/b]
[b]                redirect( base_url().'user/'.$redirect, 'refresh');[/b]
[b]            } else {[/b]
[b]                $this->session->set_flashdata('messagePr', 'You Don\'t have this autherity ' );[/b]
[b]                redirect( base_url().'user/registration', 'refresh');[/b]
[b]            }[/b]
[b]        }[/b]
[b]    [/b]
[b]    }[/b]


[b]    /**[/b]
[b]     * This function is used to delete users[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function delete($id){[/b]
[b]        is_login(); [/b]
[b]        $ids = explode('-', $id);[/b]
[b]        foreach ($ids as $id) {[/b]
[b]            $this->User_model->delete($id); [/b]
[b]        }[/b]
[b]       redirect(base_url().'user/userTable', 'refresh');[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to send invitation mail to users for registration[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function InvitePeople() {[/b]
[b]        is_login();[/b]
[b]        if($this->input->post('emails')){[/b]
[b]            $setting = settings();[/b]
[b]            $var_key = $this->randomString();[/b]
[b]            $emailArray = explode(',', $this->input->post('emails'));[/b]
[b]            $emailArray = array_map('trim', $emailArray);[/b]
[b]            $body = $this->User_model->get_template('invitation');[/b]
[b]            $result['existCount'] = 0;[/b]
[b]            $result['seccessCount'] = 0;[/b]
[b]            $result['invalidEmailCount'] = 0;[/b]
[b]            $result['noTemplate'] = 0;[/b]
[b]            if(isset($body->html) && $body->html != '') {[/b]
[b]                $body = $body->html;[/b]
[b]                foreach ($emailArray as $mailKey => $mailValue) {[/b]
[b]                    if(filter_var($mailValue, FILTER_VALIDATE_EMAIL)) {[/b]
[b]                        $res = $this->User_model->get_data_by('users', $mailValue, 'email');[/b]
[b]                        if(is_array($res) && empty($res)) {[/b]
[b]                            $link = (string) '<a href="'.base_url().'user/registration?invited='.$var_key.'">Click here</a>';[/b]
[b]                            $data = array('var_user_email' => $mailValue, 'var_inviation_link' => $link);[/b]
[b]                            foreach ($data as $key => $value) {[/b]
[b]                              $body = str_replace('{'.$key.'}', $value, $body);[/b]
[b]                            }[/b]
[b]                            if($setting['mail_setting'] == 'php_mailer') {[/b]
[b]                                $this->load->library("send_mail");[/b]
[b]                                $emm = $this->send_mail->email('Invitation for registration', $body, $mailValue, $setting);[/b]
[b]                            } else {[/b]
[b]                                // content-type is required when sending HTML email[/b]
[b]                                $headers = "MIME-Version: 1.0" . "\r\n";[/b]
[b]                                $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";[/b]
[b]                                $headers .= 'From: '.$setting['EMAIL'] . "\r\n";[/b]
[b]                                $emm = mail($mailValue,'Invitation for registration',$body,$headers);[/b]
[b]                            }[/b]
[b]                            if($emm) {[/b]
[b]                                $darr = array('email' => $mailValue, 'var_key' => $var_key);[/b]
[b]                                $this->User_model->insertRow('users', $darr);[/b]
[b]                                $result['seccessCount'] += 1;;[/b]
[b]                            }[/b]
[b]                        } else {[/b]
[b]                            $result['existCount'] += 1;[/b]
[b]                        }[/b]
[b]                    } else {[/b]
[b]                        $result['invalidEmailCount'] += 1;[/b]
[b]                    }[/b]
[b]                }[/b]
[b]            } else {[/b]
[b]                $result['noTemplate'] = 'No Email Template Availabale.';[/b]
[b]            }[/b]
[b]        }[/b]
[b]        echo json_encode($result);[/b]
[b]        exit;[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to Check invitation code for user registration[/b]
[b]     * @return TRUE/FALSE[/b]
[b]     */[/b]
[b]    public function chekInvitation() {[/b]
[b]        if($this->input->post('code') && $this->input->post('code') != '') {[/b]
[b]            $res = $this->User_model->get_data_by('users', $this->input->post('code'), 'var_key');[/b]
[b]            $result = array();[/b]
[b]            if(is_array($res) && !empty($res)) {[/b]
[b]                $result['email'] = $res[0]->email;[/b]
[b]                $result['users_id'] = $res[0]->users_id;[/b]
[b]                $result['result'] = 'success';[/b]
[b]            } else {[/b]
[b]                $this->session->set_flashdata('messagePr', 'This code is not valid..');[/b]
[b]                $result['result'] = 'error';[/b]
[b]            }[/b]
[b]        }[/b]
[b]        echo json_encode($result);[/b]
[b]        exit;[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to registr invited user[/b]
[b]     * @return Void[/b]
[b]     */[/b]
[b]    public function register_invited($id){[/b]
[b]        $data = $this->input->post();[/b]
[b]        $password = password_hash($this->input->post('password'), PASSWORD_DEFAULT);[/b]
[b]        $data['password'] = $password;[/b]
[b]        $data['var_key'] = NULL;[/b]
[b]        $data['is_deleted'] = 0;[/b]
[b]        $data['status'] = 'active';[/b]
[b]        $data['user_id'] = 1;[/b]
[b]        if(isset($data['password_confirmation'])) {[/b]
[b]            unset($data['password_confirmation']);[/b]
[b]        }[/b]
[b]        if(isset($data['call_from'])) {[/b]
[b]            unset($data['call_from']);[/b]
[b]        }[/b]
[b]        if(isset($data['submit'])) {[/b]
[b]            unset($data['submit']);[/b]
[b]        }[/b]
[b]        $this->User_model->updateRow('users', 'users_id', $id, $data);[/b]
[b]        $this->session->set_flashdata('messagePr', 'Successfully Registered..');[/b]
[b]        redirect( base_url().'user/login', 'refresh');[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to check email is alredy exist or not[/b]
[b]     * @return TRUE/FALSE[/b]
[b]     */[/b]
[b]    public function checEmailExist() {[/b]
[b]          $result = 1;[/b]
[b]          $res = $this->User_model->get_data_by('users', $this->input->post('email'), 'email');[/b]
[b]          if(!empty($res)){[/b]
[b]              if($res[0]->users_id != $this->input->post('uId')){[/b]
[b]                  $result = 0;[/b]
[b]              }[/b]
[b]          }[/b]
[b]          echo $result;[/b]
[b]          exit;[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to Generate a token for varification[/b]
[b]     * @return String[/b]
[b]     */[/b]
[b]    public function generate_token(){[/b]
[b]        $alpha = "abcdefghijklmnopqrstuvwxyz";[/b]
[b]        $alpha_upper = strtoupper($alpha);[/b]
[b]        $numeric = "0123456789";[/b]
[b]        $special = ".-+=_,[email protected]$#*%<>[]{}";[/b]
[b]        $chars = $alpha . $alpha_upper . $numeric ;            [/b]
[b]        $token = '';  [/b]
[b]        $up_lp_char = $alpha . $alpha_upper .$special;[/b]
[b]        $chars = str_shuffle($chars);[/b]
[b]        $token = substr($chars, 10,10).strtotime("now").substr($up_lp_char, 8,8) ;[/b]
[b]        return $token;[/b]
[b]    }[/b]

[b]    /**[/b]
[b]     * This function is used to Generate a random string[/b]
[b]     * @return String[/b]
[b]     */[/b]
[b]    public function randomString(){[/b]
[b]        $alpha = "abcdefghijklmnopqrstuvwxyz";[/b]
[b]        $alpha_upper = strtoupper($alpha);[/b]
[b]        $numeric = "0123456789";[/b]
[b]        $special = ".-+=_,[email protected]$#*%<>[]{}";[/b]
[b]        $chars = $alpha . $alpha_upper . $numeric;            [/b]
[b]        $pw = '';    [/b]
[b]        $chars = str_shuffle($chars);[/b]
[b]        $pw = substr($chars, 8,8);[/b]
[b]        return $pw;[/b]
[b]    }[/b]


[b]}[/b]

Model:
[b]<?php
[/b]
[b]class User_model extends CI_Model {       [/b]
[b]    function __construct(){            [/b]
[b]          parent::__construct();[/b]
[b]        $this->user_id =isset($this->session->get_userdata()['user_details'][0]->id)?$this->session->get_userdata()['user_details'][0]->users_id:'1';[/b]
[b]    }[/b]

[b]    /**[/b]
[b]      * This function is used authenticate user at login[/b]
[b]      */[/b]
[b]      function auth_user() {[/b]
[b]        $email = $this->input->post('email');[/b]
[b]        $password = $this->input->post('password');[/b]
[b]        $this->db->where("is_deleted='0' AND (name='$email' OR email='$email')");[/b]
[b]        $result = $this->db->get('users')->result();[/b]
[b]        if(!empty($result)){       [/b]
[b]            if (password_verify($password, $result[0]->password)) {       [/b]
[b]                if($result[0]->status != 'active') {[/b]
[b]                    return 'not_varified';[/b]
[b]                }[/b]
[b]                return $result;                    [/b]
[b]            }[/b]
[b]            else {             [/b]
[b]                return false;[/b]
[b]            }[/b]
[b]        } else {[/b]
[b]            return false;[/b]
[b]        }[/b]
[b]      }[/b]

[b]      /**[/b]
[b]     * This function is used to delete user[/b]
[b]     * @param: $id - id of user table[/b]
[b]     */[/b]
[b]    function delete($id='') {[/b]
[b]        $this->db->where('users_id', $id);  [/b]
[b]        $this->db->delete('users'); [/b]
[b]    }[/b]
[b]    [/b]
[b]    /**[/b]
[b]      * This function is used to load view of reset password and varify user too [/b]
[b]      */[/b]
[b]    function mail_varify() {    [/b]
[b]        $ucode = $this->input->get('code');     [/b]
[b]        $this->db->select('email as e_mail');        [/b]
[b]        $this->db->from('users');[/b]
[b]        $this->db->where('var_key',$ucode);[/b]
[b]        $query = $this->db->get('');     [/b]
[b]        $result = $query->row();   [/b]
[b]        if(!empty($result->e_mail)){      [/b]
[b]            return $result->e_mail;         [/b]
[b]        }else{     [/b]
[b]            return false;[/b]
[b]        }[/b]
[b]    }[/b]


[b]    /**[/b]
[b]      * This function is used Reset password  [/b]
[b]      */[/b]
[b]    function ResetPpassword(){[/b]
[b]        $email = $this->input->post('email');[/b]
[b]        if($this->input->post('password_confirmation') == $this->input->post('password')){[/b]
[b]            $npass = password_hash($this->input->post('password'), PASSWORD_DEFAULT);[/b]
[b]            $data['password'] = $npass;[/b]
[b]            $data['var_key'] = '';[/b]
[b]            return $this->db->update('users',$data, "email = '$email'");[/b]
[b]        }[/b]
[b]    }[/b]
[b] [/b]
[b]      /**[/b]
[b]      * This function is used to select data form table  [/b]
[b]      */[/b]
[b]    function get_data_by($tableName='users', $value='', $colum='',$condition='') {    [/b]
[b]        if((!empty($value)) && (!empty($colum))) { [/b]
[b]            $this->db->where($colum, $value);[/b]
[b]        }[/b]
[b]        $this->db->select('*');[/b]
[b]        $this->db->from($tableName);[/b]
[b]        $query = $this->db->get('');[/b]
[b]        return $query->result();[/b]
[b]      }[/b]

[b]      /**[/b]
[b]      * This function is used to check user is alredy exist or not  [/b]
[b]      */[/b]
[b]    function check_exists($table='', $colom='',$colomValue=''){[/b]
[b]        $this->db->where($colom, $colomValue);[/b]
[b]        $res = $this->db->get($table)->row();[/b]
[b]        if(!empty($res)){ return false;} else{ return true;}[/b]
[b]     }[/b]

[b]     /**[/b]
[b]      * This function is used to get users detail  [/b]
[b]      */[/b]
[b]    function get_users($userID = '') {[/b]
[b]        $this->db->where('is_deleted', '0');                  [/b]
[b]        if(isset($userID) && $userID !='') {[/b]
[b]            $this->db->where('users_id', $userID); [/b]
[b]        } else if($this->session->userdata('user_details')[0]->user_type == 'admin') {[/b]
[b]            $this->db->where('user_type', 'admin'); [/b]
[b]        } else {[/b]
[b]            $this->db->where('users.users_id !=', '1'); [/b]
[b]        }[/b]
[b]        $result = $this->db->get('users')->result();[/b]
[b]        return $result;[/b]
[b]      }[/b]

[b]      /**[/b]
[b]      * This function is used to get email template  [/b]
[b]      */[/b]
[b]      function get_template($code){[/b]
[b]          $this->db->where('code', $code);[/b]
[b]          return $this->db->get('templates')->row();[/b]
[b]    }[/b]

[b]    /**[/b]
[b]      * This function is used to Insert record in table  [/b]
[b]      */[/b]
[b]      public function insertRow($table, $data){[/b]
[b]          $this->db->insert($table, $data);[/b]
[b]          return  $this->db->insert_id();[/b]
[b]    }[/b]

[b]    /**[/b]
[b]      * This function is used to Update record in table  [/b]
[b]      */[/b]
[b]      public function updateRow($table, $col, $colVal, $data) {[/b]
[b]          $this->db->where($col,$colVal);[/b]
[b]        $this->db->update($table,$data);[/b]
[b]        return true;[/b]
[b]      }[/b]
[b]}[/b]

As you can see this is an MVC formatted code(Ive learned my lesson Big Grin ) I just have this one issue. How to get it off if possible?

Heart Heart ,
Mekaboo
Reply

#2
PLEASE use code tags around code, so that your post doesn't go on forever. Many readers will tune out!
You might also notice that trying to bold the code is self-defeating.

Your question does not make clear which line in the view is the error triggering one.

I am going to guess that $user_data[0] is undefined, and not what you expect.
Reply

#3
Why $user_data[0] ?
The function in your model has to return the details for 1 user. If you just need 1 record from a table, don't use $this-db->result(), but $this->db->row().
Then, you can address the fields inside the record like this:
PHP Code:
echo $user_data->profile_pic 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.