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();
}
请告诉我该怎么做。
谢谢
答案 0 :(得分:0)
这是因为您在打印该变量之前已经结束了foreach循环 试试这个
<label>Piih Prodi</label>
<div>
<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 $data) :?>
<?php echo '<option value="'.$data->id_prodi.'">'.$data->nama_prodi.'</option>'; ?>
// Other code ..
<div class="field">
<label>Alamat</label>
<textarea placeholder="text" name="alamat">
<?php echo $data->alamat;?>
<?php endforeach; ?>
</textarea><?php echo form_error('alamat', '<div class="ui red pointing label">', '</div>'); ?>
</div>
答案 1 :(得分:0)
这只是因为你有$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>