[英]How to get ID from site url in view page
http://localhost/cisbeadmin/index.php/conuser/edituser/.$row->$id_pegawai
如何从CodeIgniter中的网站网址获取ID? 这是我在视图页面中的代码:
<a href="<?php echo site_url('conuser/edituser/.$row->$id_pegawai'); ?> "> <i class="fa fa-edit"></i></a>
首先,您不需要直接进入视野。 您应该使用控制器的方法来获取它。 在您的情况下,方法名称为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.
希望我详细解释。 让我知道您是否对此有任何疑问。
用此替换代码
<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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.