Undefined property: stdClass alamat
在我看来,
$this->data['prodi']=$this->mprodi->get_all_prodi();
在我的控制器视图中,我得到了这个错误。但当我不采取我的选择prodi
不显示。
这是我的观点:
<div class="field">
<label>Piih Prodi</label>
<input type="hidden" name="nama_prodi" value="<?php echo $data->nama_prodi;?>"><?php echo form_error('nama_prodi', '<div class="ui red pointing label">', '</div>'); ?>
<select name="prodi" id="select_prodi">
<?php foreach ($prodi as $prodi_data) :?>
<?php echo '<option value="'.$prodi_data->id_prodi.'">'.$prodi_data->nama_prodi.'</option>'; ?>
<?php endforeach; ?>
</select>
</div>
<div class="field">
<label>Fakultas</label>
<div class="ui small left icon input">
<input type="text" disabled="disabled" id="fakultas" class="fakultas" placeholder="fakultas" name="nama_fakultas">
<i class="text file outline icon"></i>
</div>
</div>
<div class="field">
<label>Alamat</label>
<textarea placeholder="text" name="alamat">
<?php echo $data->alamat;?>
</textarea><?php echo form_error('alamat', '<div class="ui red pointing label">', '</div>'); ?>
</div>
控制器:
function edit_anggota($nim='')
{
$this->form_validation->set_rules('nim', 'nim', 'required');
$this->form_validation->set_rules('email', 'email', 'required'););
$this->form_validation->set_rules('geup', 'Geup', 'required');
//$nim = $this->uri->segment(4);
$nim = $this->input->post('old_nim');
$this->data['prodi'] = $this->mprodi->get_all_prodi();
if (!empty($_POST))
{
$data['nim'] = $this->input->post('nim');
$data['email'] = $this->input->post('email');
$data['no_telp'] = $this->input->post('no_telp');
$data['tempat_lahir'] = $this->input->post('tempat_lahir');
$data['tanggal_lahir'] = $this->input->post('tanggal_lahir');
$data['tanggal_lahir'] = $this->input->post('tanggal_lahir');
$data['jenis_kelamin'] = $this->input->post('jenis_kelamin');
$data['angkatan'] = $this->input->post('angkatan');
$data['agama'] = $this->input->post('agama');
$data['id_prodi'] = $this->input->post('id_prodi');
$data['alamat'] = $this->input->post('alamat');
$data['sabuk'] = $this->input->post('sabuk');
$data['geup'] = $this->input->post('geup');
if ($this->form_validation->run() !== FALSE)
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
if ($_FILES['userfile']['size']==0)
{
// echo "<pre>";
// print_r($_POST);
// print_r($_FILES);
// print_r($this->upload->display_errors());
// exit;
$this->mdaftar->update_daftar($nim,$data);
$this->session->set_flashdata('message', generateSuccessMessage('Data berhasil diupdate'));
redirect(site_url('anggota/profil/edit_anggota'));
}
else
{
$this->data['error']= $this->upload->display_errors();
$this->data['id_user'] = $this->session->userdata('user_id');
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['data'] = $this->mdaftar->get_daftar_detail($this->data['id_user']);
$this->data['contents'] = $this->load->view('anggota/edit_profil', $this->data, true);
$this->load->view('template/wrapper/mahasiswa/wrapper_sign',$this->data);
}
}
else
{
$datafoto=$this->upload->data();
$nm_file =$datafoto['file_name'];
$data['image']= $nm_file;
$this->mdaftar->update_daftar($nim,$data);
// print_r($this->mdaftar->update_daftar($nim,$data));
$this->session->set_flashdata('message', generateSuccessMessage('Data berhasil diupdate'));
redirect(site_url('anggota/profil/edit_anggota'));
}
}
else
{
$this->data['id_user'] = $this->session->userdata('user_id');
$this->data['detail'] = $this->mdaftar->get_daftar_detail($this->data['id_user']);
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('anggota/edit_profil', $this->data, true);
$this->load->view('template/wrapper/mahasiswa/wrapper_sign',$this->data);
}
}
else
{
$this->data['id_user'] = $this->session->userdata('user_id');
$this->data['data'] = $this->mdaftar->get_daftar_detail($this->data['id_user']);
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('anggota/edit_profil', $this->data, true);
$this->load->view('template/wrapper/mahasiswa/wrapper_sign',$this->data);
}
}
情态动词
function get_daftar_detail($id_user)//$limit = 10, $offset = 0)
{
//$this->db->order_by('id','asc');
//$this->db->limit($limit, $offset);
$this->db->select('*');
$this->db->join('prodi','prodi.id_prodi = mahasiswa.id_prodi','left');
$this->db->join('pendaftaran_anggota','pendaftaran_anggota.nim = mahasiswa.nim','left');
$this->db->join('anggota','anggota.id_anggota = pendaftaran_anggota.id_anggota','left');
$this->db->join('user','user.id_user = anggota.id_user','left');
$this->db->where('user.id_user',$id_user);
//$this->db->join('prodi','prodi.id_prodi = mahasiswa.id_prodi','join');
$data = $this->db->get('mahasiswa');
return $data->row();
}
function get_all_prodi()
{
$this->db->order_by('id_prodi','desc');
$data = $this->db->get($this->tbl_prodi);
return $data->result();
}
请告诉我该怎么做。
谢谢你
最佳答案
只是因为你有$data
变量。
$this->data['data'] = $this->mdaftar->get_daftar_detail($this->data['id_user']);
你使用
$data
-foreach
。<?php foreach ($prodi as $data) :?>
你需要改变它。
<?php foreach ($prodi as $prodi_data) :?>
<div class="field">
<label>Piih Prodi</label>
<input type="hidden" name="nama_prodi" value="
<?php echo $data->nama_prodi;?>">
<?php echo form_error('nama_prodi', '
<div class="ui red pointing label">', '</div>'); ?>
<select name="prodi" id="select_prodi">
<?php
foreach ($prodi as $prodi_data)
{
echo '<option value="'.$prodi_data->id_prodi.'">'.$prodi_data->nama_prodi.'</option>';
}
?>
</select>
</div>
<div class="field">
<label>Fakultas</label>
<div class="ui small left icon input">
<input type="text" disabled="disabled" id="fakultas" class="fakultas" placeholder="fakultas" name="nama_fakultas">
<i class="text file outline icon"></i>
</div>
</div>
<div class="field">
<label>Alamat</label>
<?php
// We need to check $data.
// Please comment what the result. Paste in comment.
var_dump($data);
?>
<textarea placeholder="text" name="alamat">
<?php echo $data->alamat;?>
</textarea>
<?php echo form_error('alamat', '<div class="ui red pointing label">', '</div>'); ?>
</div>
关于php - 未定义的属性:stdClass codeigniter,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23729909/