无法在codeigniter中将参数作为查询字符串传递

时间:2016-04-12 11:26:42

标签: php codeigniter codeigniter-2

我是codeigniter的新手我希望将参数作为查询字符串传递而不是段我已经看过其他链接但是它们没有工作。我想只在这个特定的控制器上使用查询字符串。以下是我正在使用的代码:

<a  href="<?=base_url()?>sample_qp/new_view/?id=<?=$a2?>">
 <label class="fils-label">
Reload Page
  </label>
</a>

并在控制器中:

public function new_view($id)
{   $id=$this->input->get('id');
    $data['name']=$id;
    $this->load->view('load_new_sample_view',$data);
}

我已经设置了

  

$ config [&#39; enable_query_strings&#39;] = true;和$ config [&#39; uri_protocol&#39;] =   &#34; PATH_INFO&#34 ;;但问题是我找不到404页错误。

1 个答案:

答案 0 :(得分:2)

方法01

像这样传递

<a  href="<?=base_url()?>sample_qp/new_view/<?php echo $a2 ?>">
  

确保short_url_tag已开启

在控制器中

public function new_view($id)
{
    if(empty($id))
    {
        echo "Invalid Token";
    }
    else{
        echo($id);
    }
}

方法02

<a href="<?=base_url()?>index.php?c=sample_qp&m=new_view&id=<?=$a2?>">

在application / config.php

$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

在控制器中

$id = $this->input->get('id');
echo $id ;