我需要理解为什么country_id
变量未在
public function getCountry($country_id) {
$this->db->select()->where('country_id', $country_id);
$this->db->from('country');
$query = $this->db->get();
return $query->result();
}
public function country() {
$json = array();
$country_info = $this->country->getCountry($country_id);
if ($country_info) {
$json = array(
'country_id' => $country_info['country_id'],
'name' => $country_info['name'],
'zone' => $this->country->getZonesByCountryId($country_id),
'status' => $country_info['status']
);
}
echo json_encode($json);
}
消息:未定义的变量:country_id
文件名:localization / Countries.php
行号:12
答案 0 :(得分:1)
消息:未定义的变量:country_id
这里没有定义$country_id
变量。它没有任何意义,因为还没有分配给它。它突然冒出来。
public function country() {
$json = array();
$country_info = $this->country->getCountry($country_id);
....
您必须通过为其指定值来定义它....
public function country()
{
$json = array();
$country_id = 3; // <- define it here
$country_info = $this->country->getCountry($country_id);
....
或者您可以将其作为函数的参数传递...
public function country($country_id) // <- pass it in
{
$json = array();
$country_info = $this->country->getCountry($country_id);
....