链接到codeigniter

时间:2017-09-29 08:40:11

标签: php codeigniter codeigniter-3

我正在尝试在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>&copy; kadokado 2017, Inc.</p>
</footer>
<hr>
</div>

<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>

当我加载视图页面时,我看不到用户名,也没有指向用户个人资料的链接。 这是我的控制器(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


class User_model extends CI_Model {


public function getUserInfoByEmail($email)
    {
        $q = $this->db->get_where('users', array('email' => $email), 1);  
        if($this->db->affected_rows() > 0){
            $row = $q->row();
            return $row;
        }else{
            error_log('no user found getUserInfo('.$email.')');
            return false;
        }
    }

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


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



}

?>

1 个答案:

答案 0 :(得分:0)

可原因是因为这一行:

<?=$row['username']; ?>

也许你的服务器不支持短手牌?

试试这个:

<?php echo $row['username']; ?>

你最后还错过了一个分号:

echo base_url() . 'User/profiel_user?id='.$row['user_id']

也在这里:

<a href="<?php echo base_url() ?>/Cadeauaanvragen">

您还使用没有周围表标记的表行和表数据标记。或者删除所有tr和td标签。 请参阅:How do browsers analyze <tr> <td> without <table>?