简体   繁体   English

如何从查看页面中的网站URL获取ID

[英]How to get ID from site url in view page

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

How can I get id from site url in CodeIgniter? 如何从CodeIgniter中的网站网址获取ID? This is my code in view page: 这是我在视图页面中的代码:

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

First of all you don't need to get in view directly. 首先,您不需要直接进入视野。 You should get it in controller's method. 您应该使用控制器的方法来获取它。 In your case method name is edituser 在您的情况下,方法名称为edituser

Here is a way how you can get the id from url: 这是一种从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.

Hope I explained in detail. 希望我详细解释。 Let me know if you have any issue with that. 让我知道您是否对此有任何疑问。

Replace code with this 用此替换代码

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

and after you can get id in your view as per below code 然后您可以按照以下代码在视图中获取ID

$id_pegawai = $this->uri->segment(2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM