【问题标题】:Cannot pass parameter as a query string in codeigniter无法在 codeigniter 中将参数作为查询字符串传递
【发布时间】:2016-04-12 19:42:02
【问题描述】:

我是 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['enable_query_strings'] = true;和 $config['uri_protocol'] = "PATH_INFO";但问题是我收到 404 page not found 错误。

【问题讨论】:

  • 如果你没有使用过 Apache config 或 .htaccess 是不是忘记在 url 中添加 index.php?
  • @Arjun:我已经通过 .htaccess 从 url 中删除了 index.php
  • 尝试连接值:&lt;?php echo base_url() . 'sample_qp/new_view/?id=' . $a2

标签: php codeigniter codeigniter-2


【解决方案1】:

方法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 ;

【讨论】:

  • 当我将它作为像这样projectname/controller/method/a/x/a/a/Javascript%20ios%20Adobe/… 的段传递时,我收到以下错误不可接受!在此服务器上找不到所请求资源的适当表示。此错误是由 Mod_Security 生成的。我已经搜索了很多,但找不到解决方案。
  • 你可以使用$this-&gt;uri-&gt;segment(n)n 表示价值
  • 但是 Abdulla 也导致错误 Not Acceptable 当我单击该链接时它工作正常,当它在第 5 段中只有一个单词用于例如 Javascript 时。什么是soln。为了那个原因。请帮助解决我的问题。
  • @user3653474 包括index.php。有时它没有它就会挂起
  • 更新 config.php $config['uri_protocol'] = 'REQUEST_URI';
猜你喜欢
  • 2016-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多