2016-03-15 39 views
1

我通过锚标记在笨没能获得ID在控制器

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

发送ID和我在控制器捕捉值,如:

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

但它显示了以下错误

PHP遇到错误

严重性:警告消息:缺少参数1 信息:: sectionEmpList()文件名:控制器/ Dashboard.php线 号:302回溯:

文件:d:\ XAMPP \ htdocs中\ MECON \应用\控制器\控制板.PHP 线:302功能:_error_handler

文件:d:\ XAMPP \ htdocs中\ MECON \的index.php线:292功能:require_once

任何一个可以建议如何解决。

+2

什么是路由器文件的样子?'$ id'没有传递给这个函数是错误说的,所以这个url没有被生成一个ID或者控制器没有正确处理它 – MECU

+0

获取该ID的网址,但未到达控制器 –

回答

1

其由于单引号。使用如下

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

非常感谢Vinie,它工作。 –

0

试试这个:

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

您需要的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);?>"> 

自动加载的url helper。和会话库。

您还可能需要创建一个路线。

+0

我已经在我的会话中有ID,并且我将该ID从视图传递到控制器的功能 –

+0

您没有解释在您的问题 – user4419336

+0

路由中添加了如下内容: –

0

你下application/config/router.php需要看起来像这样的路由器文件(这大致是,可能会根据您的设置不同。

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