我是codeigniter的新手。我在一個href標記中傳入一個id。我希望這個id在控制器中顯示。任何人都可以幫助我。我已經看到堆棧溢出中的類似問題,並且我嘗試了所有方法,但都沒有工作。任何人都可以幫助我。如何從codigniter的查詢字符串中獲取參數值
myController的
<?php
/**
*
*/
class Url extends CI_Controller
{
public function menu1($product_id;)
{
echo $product_id;
// $data1 = $this->uri->segment(4);
// $id['data'] =$data1;
// $this->load->view('menu1',$id);
//$this->input->get('id', TRUE);
}
public function menu2()
{
$this->load->view('menu2');
}
public function menu3()
{
$this->load->view('menu3');
}
}
?>
查看文件
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="<?php echo base_url('assets/lib/bootstrap/css/bootstrap.min.css'); ?>" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4">
<ul class="">
<?php $id=1;
?>
<li><a href='<?php echo base_url("Url/menu1?id=$id")?>' class="update">menu1</a></li>
<li><a href="<?php echo base_url('Url/menu2')?>" class="update">menu2</a></li>
<li><a href="<?php echo base_url('Url/menu3')?>" class="update">menu3</a></li>
</ul>
</div>
<div class="col-md-4">
<div id="body" class="col-lg-12" >
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="<?php echo base_url('assets/lib/jquery/jquery-1.11.2.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/lib/bootstrap/js/bootstrap.min.js'); ?>"></script>
<script>
$(function()
{
$('.update').click(function(event)
{
event.preventDefault();
//$('.update').removeClass("active");
//$(this).addClass("active");
$('#body').load($(this).attr('href'));
});
});
</script>
</html>
menu1.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php echo $data;
?>
</body>
</html>
嘗試谷歌自己的問題:https://www.google.pt/search?q= ajax%3A + how + to + get + the + parameter + value + from + the query + string + in + codigniter&ie = utf-8&oe = utf-8&client = firefox-b-ab&gfe_rd = cr&ei = LQx_WYPfM4TY8geM7bmABA – Vickel