简体   繁体   中英

View user data along with profile pic in codeigniter?

I want to show user data along with profile pic on it's profile page i am successful in displaying the profile pic but have some doubts in my mind how can i other show user data on same page should i make other controller and model for that or single controller and model is enough to perform task.If we make another model and controller for that is it possible to or good pratice to return different data one from profile_pic controller and other from user_data controller to same view.

//My profile_pic controller
 public function index() {
            if($this->session->userdata('is_login')) {


        $session_data = $this->session->userdata('sessiondata');
        $id = $session_data['user_id'];
        $this->load->model('Display_profilepicture');
        $data = $this->Display_profilepicture->getImage();
        //var_dump($data);
        print_r($data);
        //echo '<br>';
        $img = base_url().'upload/thumbs/'.$data;
        //echo $img.'<br>';
        $data = array('img' => $img);
        //print_r($data);
        //$this->load->view('header');
        //$this->load->view("my_profile", $data);
    //  $data=array('profile_picture'=>$img);
        //print_r( $data['profile_picture']);
        //echo '<br>';
        //header("Content-type: image/jpg");
        //$this->load->view('header');
        //$this->load->view('my_profile',array('data'=>$data));



        }

//my model 
function get_user_data(){
$session_data = $this->session->userdata('sessiondata');
$id = $session_data['user_id'];
$this->db->select("*");
$this->db->from('tbl_usrs');
$this->db->where('user_id', $id);
$query = $this->db->get();
if($query->num_rows()==0)
echo("Picture not found!");
else
$data = $query->result();
return $data=$query->result();
//print_r($data['profile_picture']);
}
function getImage(){
$session_data = $this->session->userdata('sessiondata');
$id = $session_data['user_id'];
$this->db->select("*");
$this->db->from('tbl_usrs');
$this->db->where('user_id', $id);
$query = $this->db->get();
if($query->num_rows()==0)
echo("Picture not found!");
else
$data = $query->row_array();
return $data['profile_picture'];
//print_r($data['profile_picture']);
} 

this is data returned from model and result of print_r($data);

Array ( [user_id] => 26 [first_name] => aman [last_name] => [username] => aman123 [sex] => [dob] => 0000-00-00 [phone] => 0 [email] => aman@gmail.com [visited_country] => 0 [about_me] => [help_others] => [fav_activity] => [bed_offer] => 0 [couch_country] => 0 [couch_state] => 0 [couch_city] => 0 [couch_addline1] => [couch_addline2] => [profile_picture] => db421e40f1c1852d8cc0acc93d7bb963.jpg [picture1] => [picture2] => [picture3] => [picture4] => [picture5] => [country] => [state] => [city] => [addline1] => [addline2] => [zip] => 0 [created_on] => 0000-00-00 [password] => 123123 [modified_on] => 0000-00-00 [active] => [user_type] => 0 [ip] => ::1 ) 

if make changes in my model set return $data instead of $data['profile_picture'] then array of data is returned but i get error array to string conversion due line in controller "$img = base_url().'upload/thumbs/'.$data;" so i just wana ask what is best way to perform task and how??Some code help is also accepted??

In controller

function index()
{
    if ( $this->session->userdata('is_login') )
    {

        $session_data = $this->session->userdata('sessiondata');
        $id = $session_data['user_id'];
        $this->load->model('Display_profilepicture');
        $result = $this->Model_name->get_user_data($id);

        if($result==0)
        {
            echo 'No user Found';
        }
        else
        {
            $data['user']=$result;
            $this->load->view('header');
            $this->load->view("my_profile", $data);
        }
    }
}

In model

function get_user_data($id)
{
    $query = $this->db->query("SELECT * FROM tbl_usrs WHERE user_id='$id'");
    $result = $query->result_array();
    $count = count($result);

    if(empty($count) || $count > 1)
    {
        $log = 0;
        return $log ;
    }
    else
    {
        return $result;
    }
}

In View

foreach ( $user as $new_user )
{
    ?>
    <h4>Your name: <?php echo $new_user['first_name'] ?> </h4>
    <img src="<?php echo base_url()?>upload/thumbs/<?php echo $new_user['profile_picture'] ?>" alt="<?php echo $new_user['first_name'] ?>">
    <p>E-Mail: <?php echo $new_user['aman@gmail.com'] ?></p>
<?php
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM