1
如何從Codeigniter網址獲取第三個參數,如http://domain.org/project/controller/view#tab-3/2。我需要訪問第三個參數值,即,在這裏,來自URL的2
。我試過$this->uri->segment(3);
,它沒有返回任何值。 $this->uri->segment(2);
返回值view
而不是view#tab-3
。無法訪問Codeigniter URL中的參數
我想要做的是CI中的分頁。在我的頁面中,我正在使用選項卡。在點擊TAB3它會調用一個Ajax功能,如下圖所示:
function receivedtickets(userid,baseurl)
{
var pagenum=$('#pagenum').val();
if(pagenum!="" && pagenum!=undefined)
{
data='userid='+userid+'&pagenum='+pagenum;
}
else
{
data='userid='+userid;
}
$.ajax({
type:'post',
url:baseurl+'video/receivedtickets/'+pagenum,
datatype:'json',
data:data,
success:function(response)
{
$('#tab-3').html(response.results);
$('#recpagination').html(response.pagination);
}
});
}
pagenum
是包含選項我的視圖頁面的隱藏字段。
if($this->uri->segment(3))
{
$data['page_num']=$this->uri->segment(3);
}
else
{
$data['page_num']=0;
}
<input type="hidden" id="pagenum" value="<?php echo $data['page_num'];?>">
的分頁控制器代碼:
function receivedtickets()
{
if (!$this->tank_auth->is_logged_in())
{ // not logged in
redirect(base_url().'auth/login');
}
$this->load->library('pagination'); // library for pagination
$userid=$_POST['userid'];
$per_pg=1;
if($this->uri->segment(3))
{
$page_num= $this->uri->segment(3);
$offset=($page_num - 1) * $per_pg;
}
else
{
$offset=0;
}
$config['base_url'] = base_url().'video/tickets#tab-3';
$config['total_rows'] = 50;
$config['div'] = '#pagination'; // div for displaying ajax
$config['per_page'] = $per_pg;
$config['uri_segment'] = 3;
$config['page_query_string'] = FALSE;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$pagination=$this->pagination->create_links();
$string="";
$query=$this->db->query("SELECT
s.send_on,
s.sendby_id,
t.ticket_key,
t.video_id,
a.first_name,
a.last_name,
v.title,
v.videothumbnail ,
s.sendto_id
FROM
sendticket AS s
LEFT JOIN ticket AS t
ON s.ticketid = t.id
LEFT JOIN auth_user_profiles AS a
ON a.user_id = s.sendby_id
LEFT JOIN video AS v
ON t.video_id = v.videoid
WHERE (s.sendto_id = $userid or s.sendto_id ='[email protected]')
ORDER BY s.send_on DESC limit $offset,$per_pg");
$string.='<div class="tableoutertb">
<table class="myticketsdivv">
<tr class="mytickets_row">
<td class="mytickets_colmn ">'.lang('video').'</td>
<td class="mytickets_colmn ">'.lang('title').'</td>
</tr>';
if($query->num_rows > 0)
{
foreach($query->result() as $row)
{
$string.='<tr class="mytickets_row">
<td class="mytickets_colmn">
<span class="mob_title">'.lang('video').'</span>
<a target="_blank" href="'.base_url().'video/playvideo/'.$row->video_id.'">';
$string.='<img src="'.base_url().'images/No_image.png" style="max-width: 140px;" alt="Teshot featured video preview">';
$string.='</a>
</td>
<td class="mytickets_colmn">
<span class="mob_title">'.lang('title').'</span>
<a target="_blank" style="color: #3b5998;" href="'.base_url().'video/playvideo/'.$row->video_id.'">'.$row->title.'</a>
</td>
</tr>';
}
$string.='<tr class="mytickets_row"><td class="mytickets_colmn" colspan="5"><div class="pagination" style="position: initial;margin-top:0px;float:right;" id="recpagination"></div></td></tr>';
}
$string.='</table>
</div>';
header('Content-type: application/json');
$ret = array();
$ret['results']=$string;
$ret['pagination']= $pagination;
echo json_encode($ret);
exit;
}
誰能幫我解決這個問題?提前致謝。
@ user574632..Thanks對您有所幫助。現在問題在於分頁url。我需要的網址是像http://domain.org/project/video/tickets/pagenumber/#tab-3 – Jenz