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

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?

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