dqwh1205 2018-10-22 16:42
浏览 56

无法通过视图中的按钮将id传递给codeigniter中的控制器

so i am trying to pass id from a link i created in views to my controller method however i get the error that unidentified variable id

below is the link in view

<a href="<?php echo base_url();?>doctors/display_schedule/<?php echo $id['d_id']; ?>" >set schedule</a>

and this is the controller method:

public function display_schedule($d_id)
    {
        $data['id'] = $this->doctor_model->get_info_by_id($d_id);
        $this->load->view("doctors_schedule_view",$data);
    }

ps, if you want a look at my model inform me

  • 写回答

3条回答 默认 最新

  • douxue4395 2018-10-22 16:51
    关注

    When passing data in this way, no matter what the variable names are you need to explicitly assign the variable in the controller otherwise i'll remain undefined.

    Let's assume:

    <a href="<?php echo base_url();?>doctors/display_schedule/<?php echo $id['d_id']; ?>" >set schedule</a>
    

    points to doctors/display_schedule/1234

    So, if you want to use 1234 you need to enable the URL helper and add this in the display_schedule method in your controller:

    $d_id = $this->uri->segment(3);

    This way, whatever was passed to the controller in the third uri segment will be assigned to $d_id in the controller.

    BE AWARE that you need to sanitize the input after assigning it to the variable in order to prevent malicious uses like code injecting and whatnot.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序