简体   繁体   English

在codeigniter中查看用户数据以及个人资料照片?

[英]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. 我想在它的个人资料页面上显示用户数据以及个人资料照片我成功地显示了个人资料照片,但我心中有些疑惑我怎么能在同一页面上显示其他控制器和模型的其他控制器和模型控制器和模型足以执行任务。如果我们为此创建另一个模型和控制器,可以或者很好地将不同的数据从profile_pic控制器和其他从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']);
} 

this is data returned from model and result of print_r($data); 这是从模型返回的数据和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;" 如果在我的模型集中进行更改返回$ data而不是$ data ['profile_picture'],则会返回数据数组,但我会在控制器“$ img = base_url()”中获得错误数组到字符串转换.'upload / thumbs / 。” $的数据;” so i just wana ask what is best way to perform task and how??Some code help is also accepted?? 所以我只是wana问什么是执行任务的最佳方式,以及如何?一些代码帮助也被接受?

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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