【问题标题】:how to redirect from view to controller and pass a variable to controller in codeigniter如何从视图重定向到控制器并将变量传递给codeigniter中的控制器
【发布时间】:2017-06-22 04:02:58
【问题描述】:

我试图从我在 codeigniter 中的视图重定向到控制器内的函数。 我使用了以下代码

redirect('front/exam_result',$id)

这里的“front”是我的控制器,“exam_result”是我在front里面的函数。 $id 是要传递的变量。 这段代码有错误吗?

【问题讨论】:

  • redirect('front/exam_result/'.<?php echo $id ?>); 试试这个
  • 它正在工作,不需要
  • 感谢您的指正。

标签: php codeigniter view controller


【解决方案1】:

您可以像这样轻松地重定向到控制器的任何功能/方法:

redirect(base_url().'控制器/方法');

如果你需要通过函数/方法传递变量,你可以这样做:

redirect(base_url().'Controller/Method/'.$variable);

在你的情况下,这将是解决方案:

redirect(base_url().'front/exam_result/'.$id);

最好使用包含的 base_url() 而不是直接链接。

【讨论】:

    【解决方案2】:

    将逗号改为点。

    redirect('front/exam_result',$id)
    

    redirect('front/exam_result'.$id)
    

    【讨论】:

    • 如果它解决了您的问题,请接受我的回答:)
    【解决方案3】:
    You can pass a variable using codeigniter querystring as follows:
    
    when you are using redirect method :
    
    redirect(base_url().'controller/method/'.<?php echo $variable; ?>);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多