I got error in codeigniter and I dont know how to solve this. My error is:- A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/umparam.php
Line Number: 25
controller code:
public function edit($record_mpid)
{
$this->load->model('mparam');
$record = $this->mparam->getAllRecords($record_mpid);
$this->load->view('umparam',['record'=>$record]);
}
}
Model code:
public function getAllRecords($record_mpid)
{
$query = $this->db->get_where('mparam', array('mpid'=> $record_mpid));
if ( $query->num_rows() > 0){
return $query->row();
}
}
}
view code:
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Parameter</label>
<div class="col-md-6">
<?php echo form_input(['name'=>'parameter','class'=>'form-control','placeholder'=>'Parameter','value'=>set_value('parameter', $record->parameter)]); ?> // line no 25
</div>
<div class="col-md-6">
<?php echo form_error('parameter'); ?>
</div>
</div>
Please help.Thank you!!
On your controller function
public function edit($record_mpid) {
$this->load->model('mparam');
$data['record'] = $this->mparam->getAllRecords($record_mpid);
$this->load->view('umparam', $data);
}
Then on view
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Parameter</label>
<div class="col-md-6">
<?php
$att = array(
'name' => 'field_name',
'class' => 'form-control',
'placeholder' => 'Enter something',
'value' => set_value('field_name', $record->parameter)
);
echo form_input($att);
?>
</div>
<div class="col-md-6">
<?php echo form_error('field_name', '<p>', '</p>'); ?>
</div>
</div>
Model
public function getAllRecords($record_mpid) {
$this->db->where('mpid', $record_mpid);
$query = $this->db->get('mparam');
if ($query->num_rows() > 0) {
return $query->row(); // will return single item;
}
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.