获取传入的参数 URL Codeigniter
Get parameter passed in URL Codeigniter
基本上我有一个锚标记(更新),它获取 table 中请求的 ID 并加载更新视图获取所有请求详细信息
<a href="<?php echo base_url('dashboard/staff/request/update_request_view/'.$drafts['idx']);?>" class="btn waves-effect waves-light btn-info update-button <?php if($drafts['status']=='ONGOING'){echo 'disableClick';}?>"><i class="fa fa-eye"></i> Update</a>
然后在我的方法中收到这个
public function update_request_view($idx)
{
//some code here to load the view and get details
}
然后url就变成了http://localhost/dashboard/staff/request/update_request_view/48
现在,当我尝试使用另一种方法保存更新时
public function update()
{
$idx = $this->uri->segment(5);
}
我的 $idx
变量是空的。当我使用 $this->uri->segment(4)
时,我得到 update_request_view.
我不想使用隐藏字段,因为它会导致很多安全问题,而且当我能够解决这个问题时,我会加密 ID。为什么我的 $this->uri->segment(5)
是空的,如何获取?
如果我理解正确的话,很可能是因为 update
函数与 http://localhost/dashboard/staff/request/update_request_view/48
函数是一个单独的页面。所以 CI 没有看到任何先前的 url 变量。您可以提交给 update/{$id}
(操作 url)或者您 可以 使用隐藏字段;它与在 url 中使用 id 一样安全,因为可以通过更改表单操作轻松地操纵它。
也就是说,如果您真的很关心安全性,您应该使用某种 ACL 限制特定用户对给定记录的访问。
基本上我有一个锚标记(更新),它获取 table 中请求的 ID 并加载更新视图获取所有请求详细信息
<a href="<?php echo base_url('dashboard/staff/request/update_request_view/'.$drafts['idx']);?>" class="btn waves-effect waves-light btn-info update-button <?php if($drafts['status']=='ONGOING'){echo 'disableClick';}?>"><i class="fa fa-eye"></i> Update</a>
然后在我的方法中收到这个
public function update_request_view($idx)
{
//some code here to load the view and get details
}
然后url就变成了http://localhost/dashboard/staff/request/update_request_view/48
现在,当我尝试使用另一种方法保存更新时
public function update()
{
$idx = $this->uri->segment(5);
}
我的 $idx
变量是空的。当我使用 $this->uri->segment(4)
时,我得到 update_request_view.
我不想使用隐藏字段,因为它会导致很多安全问题,而且当我能够解决这个问题时,我会加密 ID。为什么我的 $this->uri->segment(5)
是空的,如何获取?
如果我理解正确的话,很可能是因为 update
函数与 http://localhost/dashboard/staff/request/update_request_view/48
函数是一个单独的页面。所以 CI 没有看到任何先前的 url 变量。您可以提交给 update/{$id}
(操作 url)或者您 可以 使用隐藏字段;它与在 url 中使用 id 一样安全,因为可以通过更改表单操作轻松地操纵它。
也就是说,如果您真的很关心安全性,您应该使用某种 ACL 限制特定用户对给定记录的访问。