0
http://localhost/cisbeadmin/index.php/conuser/edituser/.$row->$id_pegawai

如何从 CodeIgniter 中的站点 url 获取 id?这是我在视图页面中的代码:

<a href="<?php echo site_url('conuser/edituser/.$row->$id_pegawai'); ?>  "> <i class="fa fa-edit"></i></a>
4

2 回答 2

0

首先,您不需要直接进入视图。你应该在控制器的方法中得到它。在您的情况下,方法名称是edituser

这是一种从 url 获取 id 的方法:

// Make sure your segment possition is correct and place few lines of code in starting of your method edituser()
$id = $this->uri->segment(3)) != '' && is_numeric($this->uri->segment(3)) && $this->uri->segment(3) > 0 ? $this->uri->segment(3) : false;

// After getting $id check if it is false or having value in it
if($id == false){
// If URL does not having id then it should show 404 error which is done by below line
   show_404();
}

// Pass $id value for view file same as we pass other values.

希望我详细解释。如果您对此有任何问题,请告诉我。

于 2017-05-03T19:30:01.670 回答
0

用这个替换代码

<a href="<?php echo site_url('conuser/edituser/'.$row->$id_pegawai); ?>  "> <i class="fa fa-edit"></i></a>

之后你可以按照下面的代码在你的视图中获取 id

$id_pegawai = $this->uri->segment(2);
于 2017-05-04T09:04:52.597 回答