dongzhi1904 2013-06-16 12:45
浏览 41
已采纳

如何从网址获取参数? 或更好的方法来做到这一点

im creating a function to delete a contact record, then once deleted go to the view company page.

so here is my controller public function delete($id) {

        if (isset($_GET["delete"]))
        {
            $this->Contacts_model->delete($id);
            $url = "/company/view/" . $cid;
            redirect($url);
        }

}

and here is my model

 public function delete($id)    
{

            $this->db->where('id', $id);
            $this->db->delete('contacts');
}

on my view:

<a href="/contacts/delete/<?php  echo $data['id']; ?>

which this works and will delete the contact, but obviously wont redirect to the company/view page becuase the CID isnt being passed.

i thought about adding this to the delete link

<a href="/contacts/delete/<?php  echo $data['id']; ?>?delete&cid=<?php  echo $data['cid']; ?>"   

so that cid is being passed through the url. would this work some way?

  • 写回答

1条回答 默认 最新

  • douguangxiang0363 2013-06-16 12:59
    关注

    You can pass the cid in the url like

    <a href="/contacts/delete/<?php  echo $data['id']; ?>/<?php  echo $data['cid']; ?>">delete</a>
    

    In your controller function get the second parameter as $cid or from uri segment

    public function delete($id,$cid) {
        if (isset($_GET["delete"]))
        {
            $this->Contacts_model->delete($id);
            $url = "/company/view/" . $cid;
            redirect($url);
        }
    
     }
    

    Here is uri segment documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动