컨트롤러에서 조직 이름을 얻을 수 있지만보기에 전달하면 오류가 있습니다. foreach()에 대해 잘못된 인수가 제공되었습니다.컨트롤러에서 변수로 변수를 전달합니다.
이것은 내 코드입니다.
컨트롤러
public function index()
{
$user_id = $this->session->userdata('user_id');
$data['title'] = "User";
$getID['orgID'] = $this->userModel->getOrganizationID($user_id); // used my session user_id to
foreach ($getID['orgID'] as $orgID)
{
$org_id = $orgID->org_id;
$getName['myOrganization'] = $this->userModel->myOrganization($org_id);
foreach($getName['myOrganization'] as $orgName)
{
$name = $orgName->org_name;
$data['name'] = $name;
}
}
$this->load->view('xxxx/xxxx/xxxx',$data);
모델
public function getOrganizationID($user_id)
{
$this->db->select('org_id');
$this->db->from('organization_members');
$this->db->where('user_id', $user_id);
$query = $this->db->get();
return $query->result();
}
public function myOrganization($org_id)
{
$this->db->select('org_name');
$this->db->from('tblorganization');
$this->db->where('org_id', $org_id);
$query = $this->db->get();
return $query->result();
}
먼저 배열 $ getID [ 'orgID'] 내 결과 = $ this-> userModel -> getOrganizationID ($ user_id); user_id 세션을 사용하여 사용자의 모든 org_id를 가져 왔습니다.
두 번째 배열은 $ getName [myOrganization '] = $ this-> userModel-> myOrganization ($ org_id); 나는 org_id (이전의 메서드에서)를 사용하여 사용자의 모든 org_name을 가져 왔습니다.
'$ this-> userModel-> myOrganization ($ org_id)'의 반환 값은 무엇입니까? –
또한 전달하는'$ ord_id' 매개 변수의 값은 무엇입니까? – Goose
$ org_id는 $ this-> userModel-> myOrganization ($ org_id)에 전달됩니다. $ this-> userModel-> myOrganization ($ org_id)의 리턴 값은 int입니다. 문자열의 배열, 내 출력을 확인하십시오. – Holow