Php 参数太少,无法正常工作

Php 参数太少,无法正常工作,php,codeigniter,Php,Codeigniter,控制器: public function hapus ($id) { $where = array ('id' => $id); $this->P_pejabat->hapus_data($where, 'pjbt'); redirect ('pejabat/index'); } 观点: <td><?php echo anchor('pejabat/hapus/'.$pjb->id, '<div class=&qu

控制器:

    public function hapus ($id)
{
    $where = array ('id' => $id);
    $this->P_pejabat->hapus_data($where, 'pjbt');
    redirect ('pejabat/index');
}
观点:

<td><?php echo anchor('pejabat/hapus/'.$pjb->id, '<div class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></div>') ?></td>
          
在应用程序\config\routes.php文件中设置:

$route['hapus/(:any)']='pejabat/hapus/$1';
然后,您可以在视图中使用类似的:


由于您设置的路径,锚现在重定向到控制器
pejabat
函数
hapus($id)
提供必要的变量
$1
,您在函数中将其捕获为
$id

函数参数设置为null,类似于公共函数hapus($id=null)若您传递值,那个么该值将被设置为空值。@JimitH。那么,我该怎么办?@JimitH我认为这不是一个好的解决方案,因为该方法似乎需要设置
$id
。@MagnusEriksson是它的默认参数概念。如果您确定值始终获得该时间,则无需设置默认参数。@JimitH.-是的,如果您查看该方法,它需要为其设置一个id,以便能够加载正确的数据,因此,他们应该修复该请求,确保id被传递,而不是在没有id的情况下调用该方法(在这种情况下,它将无法获取和呈现数据)。
anchor('hapus/'.$pjb->id,'etc..');