dongqing8765 2016-09-07 17:27
浏览 13
已采纳

Codeigniter从URL传递值

Function receives departure date and adult from view page ( it passes value correctly as I have checked doing echo function ) , but from this function I am not able to pass values to another function

public function index()
{

    if ($data = $this->input->post('muktinath')) {

        $date = $data['departure_on'];
        $adult = $data['adult'];

        $getNameValue = array(
            $date = 'departure_on',
            $adult = 'adult',
        );

        redirect('booking/muktinath/' . $getNameValue);
    }

    else{
        $this->load->view('index');
    }
}

This is the function which must receive the value

public function muktinath($getNameValue)
{
    echo $getNameValue; 

    // here value must be shown of departure date and adult passed from above

}
  • 写回答

2条回答 默认 最新

  • douxuanwei1980 2016-09-07 20:43
    关注

    You didn't share the error messages you are getting. Bet there several.

    The biggest issue is you cannot put an array as a part of your query string. But the fix is pretty easy.

    function index()
    {
        $data = $this->input->post('muktinath'); 
        if($data)
        {
            //From your question $data seems to be an array already. Just use that!
            redirect('booking/muktinath/'.$data['departure_on'].'/'.$data['adult']);
        }
        else
        {
            $this->load->view('index');
        }
    }
    

    Your function that receives the values is then defined this way.

    public function muktinath($date, $name)
    {
        echo $date . " - " . $name;
    }
    

    You will have a problem if $date contains any slashes (/) in what I assume is a date string. The slashes will become part of the URL which, if the date was "7/9/2016" and name was "sandesh" would make this URL.

    http://example.com/booking/muktinath/7/9/2016/sandesh

    As you can see, it has several more URI segments than you are expecting. This URL would echo "7 - 9" which is not very helpful. You might have to adjust the format of the date while sending it and then reformat it after it is received by muktinath().

    By the way, your array declaration is wrong. I think you were trying to make this.

    $getNameValue = array(
       'departure_on' => $date,
       'adult' => $adult
       );
    

    The thing is, you have just recreated what $data already was. But you don't need $getNameValue anyway.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看