如何从codeigniter中的URL获取id? [英] How to get id from URL in codeigniter?
问题描述
我想从网址获取id,以删除该特定的选定产品。我已经使用 $ this-> uri-> segment(3)
,但它没有从URL获取任何值。
如果我使用 $ this-> url-> segment(2) / code>它给我的第二个值形式URL,但我无法获得产品Id。
下面是我的代码。请指导我。
VIEW
echo< a href ='delete_controller?product_id = $ product_id'>;
echo $ name;
echo< / a>;
点击$ name时会生成以下URL。
http://localhost/designs2/index.php/products_controller/delete_controller?product_id = 70
控制器
public function delete_controller
{
echo $ product_id = $ this-> uri-> segment(3);
echoTaha;
$ this-> load-> view('delete_confirmation');
}
值应该像这样输入url
localhost / yoururl / index.php / products_controller / delete_controller / 70
并且在控制器函数中你可以这样读取
function delete_controller($ product_id = NULL){
echo $ product_id;
}
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');
}
解决方案 if you have to pass the value you should enter url like this
localhost/yoururl/index.php/products_controller/delete_controller/70
and in controller function you can read like this
function delete_controller( $product_id = NULL ) {
echo $product_id;
}
这篇关于如何从codeigniter中的URL获取id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!