无法在控制器中获取 ID


Not able to get id in controller

我正在通过代码点火器中的锚标记发送ID

<a href='sectionEmpList/".$post_array['userSecId']."'>

我正在捕获控制器中的值,例如:

public function sectionEmpList($id){ 
    $secID = $id;
    echo $secID;  
}

但它显示以下错误

遇到 PHP 错误

严重性:警告消息:缺少参数 1 Dashboard::sectionEmpList() 文件名: controllers/Dashboard.php Line 编号: 302 回溯:

File: D:''xampp''htdocs''mecon''application''controllers''Dashboard.php 行: 302 功能: _error_handler

文件: D:''

xampp''htdocs''mecon''index.php 行: 292 功能: require_once

任何人都可以建议解决方案是什么。

由于单引号。 使用方法如下

$url = $post_array['userSecId'];
<a href='sectionEmpList/'.$url>

您需要将 id 传递给视图

public function sectionEmpList(){ 
    $data['secID'] = $this->session->userdata('id');
    $this->load->view('some_view', $data);
}

然后展出

<a href="<?php echo base_url('your_controller/function/'. $secID);?>">

自动加载网址帮助程序。和会话库。

您可能还需要创建路由。

您的路由器文件需要看起来像这样application/config/router.php(这大致不同,可能会有所不同,具体取决于您的设置。

$route['sectionEmpList/(:any)='] = 'YOURCONTROLLERHERE/sectionEmpList/$1';

试试这个:

<a href='sectionEmpList/'".$post_array['userSecId']."'>