我试图在CodeIgniter框架中创建一个功能,以便用户可以点击产品详细信息页面,看看哪个用户上传了某个产品,他们必须能够点击产品所有者才能转到他的个人资料页。
现在,我已经能够在详细信息页面上回显产品所有者的所有者信息。但是,所有者个人资料页面的链接无法正常工作,因为我试图将其作为链接,因此名称不再响应。
这是我的产品详情页面(details.php)foreach循环功能,我试图回应产品所有者的用户名并将其链接到他们的个人资料页面:
<?php include_once ('templates/header.php'); ?>
<div class="container">
<h3>Email van de eigenaar:</h4>
<?php
foreach ($userdetail_list as $row) {
?>
<tr>
<td><?php echo $row['email']; ?></td>
</tr>
<?php } ?>
</div>
<div class="container">
<div class="row">
<div class="col-md-4" style="margin-top:24px;">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto']; ?>" class="img-responsive">
</div>
<div class="col-md-5">
<h1> <div class="product_naam"> <?php echo $product['product_naam']; ?> </div> </h1>
<h3>Over dit cadeau</h3>
<div class="product_beschrijving"><?php echo $product['product_beschrijving']; ?> </div>
</div>
<div class="col-md-3">
<a href="<?php echo base_url() ?>/Cadeauaanvragen"> <button type="button" class="btn btn-default">Cadeau aanvragen</button></a>
<div class="aangeboden_door"> Aangeboden door: <?php
foreach ($userdetail_list as $row) { ?>
<tr>
<td><a href="<?php echo base_url() . 'User/profiel_user?id=' . $row['user_id'] ?>"><?= $row['username']; ?></a></td>
<td><?php echo $row['email']; ?></td>
</tr>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="container">
<footer>
<p>© kadokado 2017, Inc.</p>
</footer>
<hr>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
当我加载此视图文件时,我确实看到了echoeod电子邮件,但没有看到用户名?并且也没有指向用户个人资料页面的链接..
这是我的控制器文件(User.php):
<?php
class User extends CI_Controller {
public function index() {
$this->load->view('profile', $data);
}
public function __construct() {
parent::__construct();
if ($_SESSION['user_logged'] == FALSE) {
$this->session->set_flashdata("error", "Please login first to view this page!! ");
redirect("auth/login");
}
}
public function userdetails($user_id) {
//load the User_model
$this->load->model('User_model');
//call function getdata in de Product_model
$data['userdata_list'] = $this->User_model->getdata();
//get product details
$data['user'] = $this->User_model->get_user_info($user_id);
//laad view
$data['main_content'] = 'profiel_user';
$this->load->view('profiel_user', $data);
}
public function profile() {
$this->load->model('User_model');
if ($_SESSION['user_logged'] == FALSE) {
$this->session->set_flashdata("error", "Please login first to view this page!! ");
redirect("auth/login");
}
$this->load->view('profile');
}
}
?>
这是我的模型(User_model.php):
<?php
public function getdata()
{
$this->db->where('user_id', $id);
$this->db->from('users');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result_array();
}
}
public function getUserInfo($user_id) {
$q = $this->db->get_where('users', array('user_id' => $user_id), 1);
if ($this->db->affected_rows() > 0) {
$row = $q->row();
return $row;
} else {
error_log('no user found getUserInfo(' . $user_id . ')');
return false;
}
}
?>
数据库信息:
I have 2 tables:
users:
user_id
voornaam
achternaam
email
password
(products:
product_id
product_name
product_description)
我希望有人可以帮助我, 谢谢!
答案 0 :(得分:0)
您正在将锚标记herf
中的用户名连接起来,并在<a>
和</a>
之间进行书写
更改您的代码如下:
<tr>
<td><a href="<?php echo base_url() . 'User/profiel_user?id='.$row['user_id']?>"><?=$row['username']; ?></a></td>
<td><?php echo $row['email'];?></td>
</tr>
答案 1 :(得分:0)
您可以针对您的问题尝试此解决方案。
请更改您的视图文件。
details.php
<tr>
<td><a href="<?php echo base_url() ?>User/profiel_user/'<?php $row['user_id'] ?>"><?= $row['username']; ?></a></td>
<td><?php echo $row['email']; ?></td>
</tr>
请更改您的控制器功能:
user.php的
<?php
public function profiel_user($user_id) {
$this->load->model('User_model');
if ($_SESSION['user_logged'] == FALSE) {
$this->session->set_flashdata("error", "Please login first to view this page!! ");
redirect("auth/login");
}
$data['user_id'] = $user_id; // you can used user id for getting data
$this->load->view('profile');
}
?>
由于