Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
813 views
in Technique[技术] by (71.8m points)

php - How to get id from URL in codeigniter?

I am trying to get 'id' from URL in order to delete that specific selected product. I have used $this->uri->segment(3) but its not getting any value from URL. Although i can see the 'product_id' in my URL.

If i used $this->url->segment(2) it gives me the second value form URL, but i am unable to get product Id. Following is my code. Kindly guide me.

VIEW

echo "<a href='delete_controller?product_id=$product_id'>";
echo $name;
echo "</a>";

The following URL is generating when i click on $name.

http://localhost/designs2/index.php/products_controller/delete_controller?product_id=70

Controller

public function delete_controller()
    {
        echo $product_id =$this->uri->segment(3);           
        echo "Taha";
        $this->load->view('delete_confirmation');
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check the below code hope that you get your parameter

echo $this->uri->segment('3');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...