我有一个代码,如下所示,其中包含uri,并假设uri通过的是http://website.com/accounts/school/index/fr_id/1/stateID/14683/school_name/BANGALORE国际学校(UOL)/
$uri=$this->uri->uri_to_assoc(4);
if(isset($uri['fr_id'])) { $fr_id=$uri['fr_id']; }
else{ $fr_id=''; }
if(isset($uri['stateID'])) { $stateID=$uri['stateID']; }
else{ $stateID=''; }
if(isset($uri['school_name'])) { $school_name=$uri['school_name']; }
else{ $school_name='';
echo $fr_id.$stateID.$school_name;exit;
}
使用此声明,$ uri = $ this-> uri-> uri_to_assoc(4);我无法获取在url中传递的值,需要使用if语句进行检查。任何人都可以帮我解决这个问题吗?当我回显$ fr_id,$ stateID和$ school_name的值时,它们是空的。
答案 0 :(得分:1)
希望这会对您有所帮助:
这样做:
$uri = $this->uri->uri_to_assoc(3);
/* OR simply use this */
$uri = $this->uri->uri_to_assoc();
$fr_id = ! empty($uri['fr_id']) ? $uri['fr_id'] : '';
$stateID = ! empty($uri['stateID']) ? $uri['stateID'] : '';
$school_name = ! empty($uri['school_name']) ? $uri['school_name'] : '';
echo $fr_id.' '.$stateID.' '.$school_name;die;
/*Output - 1 14683 BANGALORE*/
更多信息:https://www.codeigniter.com/userguide3/libraries/uri.html#CI_URI::uri_to_assoc
答案 1 :(得分:1)
public function function_name()
{
$uri = $this->uri->uri_to_assoc();
echo $pp=$uri['stateID'];
echo $school_name=$uri['school_name'];
echo $fr_id=$uri['fr_id'];
}
它会正常工作