在 codeigniter 中查看用户数据和个人资料图片?

View user data along with profile pic in codeigniter?

我想在它的个人资料页面上显示用户数据和个人资料图片我成功地显示了个人资料图片,但我心里有一些疑问我应该如何在同一页面上显示用户数据我应该制作其他控制器和该模型或单个控制器和模型足以执行 task.If 我们为此制作另一个模型和控制器是否有可能或很好地实践来自 profile_pic 控制器和其他数据的 return 不同数据从 user_data 控制器到同一视图。

//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']);
} 

这是 return 模型的数据和 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 ) 

如果更改我的模型集 return $data 而不是 $data['profile_picture'] 然后数据数组被 returned 但我在控制器“$img = base_url().'upload/thumbs/'.$data;”中收到错误的数组到字符串转换到期行所以我只是想问一下什么是执行任务的最佳方式以及如何?一些代码帮助也被接受了??

在控制器中

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);
        }
    }
}

模型中

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;
    }
}

在视图中

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
}