【问题标题】:How to get ID from site url in view page如何从视图页面中的站点 url 获取 ID
【发布时间】:2017-05-03 19:19:14
【问题描述】:
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>

【问题讨论】:

    标签: php html database codeigniter adminlte


    【解决方案1】:

    首先,您不需要直接进入视图。你应该在控制器的方法中得到它。在您的情况下,方法名称是 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.
    

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

    【讨论】:

      【解决方案2】:

      用这个替换代码

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

      【讨论】:

        猜你喜欢
        • 2016-03-22
        • 1970-01-01
        • 2020-10-03
        • 1970-01-01
        • 1970-01-01
        • 2020-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多