首页 > 解决方案 > 参数太少而无法发挥作用

问题描述

控制器:

    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>
          

它显示如下: 消息:

消息:函数 Pejabat::hapus() 的参数太少,在第 532 行的 C:\xampp\htdocs\ci\system\core\CodeIgniter.php 中传递了 0,而预期正好为 1

标签: phpcodeigniter

解决方案


在 application\config\routes.php 文件中设置路由:

$route['hapus/(:any)']='pejabat/hapus/$1';

然后您可以在视图中使用锚点,例如:

anchor('hapus/'.$pjb->id,'etc..');

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


推荐阅读