gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 21:57:33 24 4
gpt4 key购买 nike

我想在它的个人资料页面上显示用户数据和个人资料图片 我成功地显示了个人资料图片,但我心中有一些疑问 我应该如何在同一页面上显示其他用户数据 我应该制作其他 Controller 和模型那个或单个 Controller 和模型足以执行任务。如果我们为此制作另一个模型和 Controller ,是否有可能或良好的实践将不同的数据从 profile_pic Controller 和另一个从 user_data Controller 返回到同一 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']);
}

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

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

最佳答案

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

在模型中

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

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

关于php - 在 codeigniter 中查看用户数据和个人资料图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31944043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com