我在控制器中有这样的功能。我需要将$data1['hasil1']
的结果插入tampilInduk。
public function sikap(){
$person=$this->session->userdata('idperson');
$data1['hasil1']=$this->M_Guru->tampilNik($person);
$data2['hasil2']=$this->M_Guru->tampilInduk($data1);
$this->load->view('sidebarGuru');
$this->load->view('navbarGuru');
$this->load->view('kompetensiSikap',$data1+$data2);
}
我有这样的模型代码
public function tampilInduk($data1){
$this->db->select('induk');
$this->db->from('kelas b');
$this->db->join('siswa_kelas c','c.namakelas= b.namakelas','c.thnakademik=b.thnakademik','c.kdtingkat=b.kdtingkat','right');
$this->db->where('nik',$data1);
$data = $this->db->get(); //mengambil seluruh data
return $data->result();
}
public function tampilNik($person){
$this->db->select('nik');
$this->db->from('guru');
$this->db->where('idperson',$person);
$data=$this->db->get();
return $data->row()->nik;
}
但是错误提示该变量需要首先转换为字符串。您能帮助我如何将数组转换为字符串吗?
答案 0 :(得分:1)
这应该有效:
public function sikap(){
$person=$this->session->userdata('idperson');
$data1['hasil1']=$this->M_Guru->tampilNik($person);
$data2['hasil2']=$this->M_Guru->tampilInduk($data1['hasil1']);
$this->load->view('sidebarGuru');
$this->load->view('navbarGuru');
$this->load->view('kompetensiSikap',$data1+$data2);
}
public function tampilInduk($nik){
$this->db->select('induk');
$this->db->from('kelas b');
$this->db->join('siswa_kelas c','c.namakelas= b.namakelas','c.thnakademik=b.thnakademik','c.kdtingkat=b.kdtingkat','right');
$this->db->where('nik',$nik);
$data = $this->db->get(); //mengambil seluruh data
return $data->result();
}
public function tampilNik($person){
$this->db->select('nik');
$this->db->from('guru');
$this->db->where('idperson',$person);
$data=$this->db->get();
return $data->row()->nik;
}
答案 1 :(得分:0)
您可以使用$this->db->where('nik',$data1['hasil1']);
代替$this->db->where('nik',$data1);
答案 2 :(得分:0)
您可以尝试解决此问题的方法:
public function tampilInduk($data1) {
$this->db->select('induk');
$this->db->from('kelas b');
$this->db->join('siswa_kelas c', 'c.namakelas= b.namakelas', 'c.thnakademik=b.thnakademik', 'c.kdtingkat=b.kdtingkat', 'right');
$this->db->like('nik',$data1['hasil1']);
$data = $this->db->get(); //mengambil seluruh data
return $data->result();
}
我希望它会有所帮助。