Welcome Guest, Not a member yet? Register   Sign In
Creating default object warning
#1

I am getting the ‘creating default object from empty value’ warning message. I understand that it is warning me that an object is not declared and requires a declaration  like
<item>  = new stdClass();
However I don’t understand what is not declared as $id is passed as a parameter and the correct values get displayed. And $this already has values.
 
A PHP Error was encountered
Severity: Warning
Message: Creating default object from empty value
Filename: controllers/customers.php
Line Number: 139
Backtrace:

Below is the code.
 
 
Customers.php function
 
                function update($id)
                {
                                // set validation properties
                                $this->_set_fields();
                                //prefill form values
                                $customers = $this->customersModel->get_by_id($id)->row();
                                $this->validation->id = $id;       ß--- Line 139
                                $this->validation->firstname = $customers->cust_FirstName;
                                $this->validation->lastname = $customers->cust_LastName;
                                $this->validation->phone = $customers->cust_Phone;
                                $this->validation->add1 = $customers->cust_Add1;
                                $this->validation->add2 = $customers->cust_Add2;
                                $this->validation->city = $customers->cust_City;
                                $this->validation->state = $customers->cust_State;
                                $this->validation->postalcode = $customers->cust_PostalCode;
 
                                // set common properties
                                $data['title'] = 'Update customers';
                                $data['message'] = '';
                                $data['action'] = site_url('customers/updatecustomers');
                                $data['link_back'] = anchor('customers/index/', 'Back to list of customerss', array('class'=>'back'));
                                //load view
                                $viewdata['content'] = $this->load->view('customersEdit', $data, TRUE);
                                $this->load->view('template', $viewdata);
                }
 
function _set_fields()
                {
                                $fields= array(
                                                array(
                                                                'field' => 'id',
                                                                'label' => 'cust_ID'
                                                ),            
                                                array(
                                                                'field' => 'firstname',
                                                                'label' => 'cust_FirstName',
                                                                'rules' => 'required'
                                                ),            
                                                array(
                                                                'field' => 'lastname',
                                                                'label' => 'cust_LastName',
                                                                'rules' => 'required'
                                                ),            
                                                array(
                                                                'field' => 'phone',
                                                                'label' => 'cust_Phone'
                                                ),            
                                                array(
                                                                'field' => 'add1',
                                                                'label' => 'cust_Add1'
                                                ),            
                                                array(
                                                                'field' => 'add2',
                                                                'label' => 'cust_Add2'
                                                ),            
                                                array(
                                                                'field' => 'city',
                                                                'label' => 'cust_City'
                                                ),            
                                                array(
                                                                'field' => 'state',
                                                                'label' => 'cust_State'
                                                ),            
                                                array(
                                                                'field' => 'postalcode',
                                                                'label' => 'cust_PostalCode'
                                                )             
                                );
                               
                                $this->form_validation->set_rules($fields);
                                $this->form_validation->run();
                }
Reply
#2

Yea, bad practice not making a new object.

Just do:

$this->validation = new stdClass();
Reply




Theme © iAndrew 2016 - Forum software by © MyBB