0
votes

I'm face a new Problem in Codeigniter Framework. Her is my Out put

Array
(
    [id] => 2
    [firstname] => Maruf
    [lastname] => Ifftekhar
    [slug] => 
    [email] => [email protected]
    [email_subscribe] => 1
    [self] => 
    [phone] => 01767820010
    [company] => Russel Host
    [default_billing_address] => 
    [default_shipping_address] => 
    [ship_to_bill_address] => true
    [password] => 0689d59aa30bdca7207db3d449255650
    [active] => 1
    [group_id] => 1
    [confirmed] => 0
    [group_discount_formula] => - 0
    [expire] => 1380390903
)
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/secure.php

Line Number: 46
abida Sultana

Here is Controller

`$`email = `$`this->input->post('email');
`$`password = `$`this->input->post('password');
`$`remember = `$`this->input->post('remember');
`$`redirect = `$`this->input->post('redirect');
`$`login = `$`this->Customer_model->login(`$`email, `$`password, `$`remember);
   echo '/pre>-----';
   print_r(`$`login);
   echo 'abida Sultana'.`$`login->last_name; --------------------Line Number: 46
   exit();

and Model is

function login(`$`email, `$`password, `$`remember = false) {
    `$`this->db->select('*');
    `$`this->db->where('email', `$`email);
    `$`this->db->where('active', 1);
    `$`this->db->where('password', md5(`$`password));
    `$`this->db->limit(1);
    `$`result = `$`this->db->get('customers');
    `$`customer = `$`result->row_array();

    if (`$`customer) {

        // Retrieve customer addresses
        `$`this->db->where(array('customer_id' => `$`customer['id'], 'id' => `$`customer['default_billing_address']));
        `$`address = `$`this->db->get('customers_address_bank')->row_array();
        if (`$`address) {
            $fields = unserialize($address['field_data']);
            $customer['bill_address'] = $fields;
            $customer['bill_address']['id'] = $address['id']; // save the addres id for future reference
        }

        $this->db->where(array('customer_id' => $customer['id'], 'id' => $customer['default_shipping_address']));
        $address = $this->db->get('customers_address_bank')->row_array();
        if ($address) {
            $fields = unserialize($address['field_data']);
            $customer['ship_address'] = $fields;
            $customer['ship_address']['id'] = $address['id'];
        } else {
            $customer['ship_to_bill_address'] = 'true';
        }


        // Set up any group discount 
        if ($customer['group_id'] != 0) {
            $group = $this->get_group($customer['group_id']);
            if ($group) { // group might not exist
                if ($group->discount_type == "fixed") {
                    $customer['group_discount_formula'] = "- " . $group->discount;
                } else {
                    $percent = (100 - (float) $group->discount) / 100;
                    $customer['group_discount_formula'] = '* (' . $percent . ')';
                }
            }
        }

        if (!$remember) {
            $customer['expire'] = time() + $this->session_expire;
        } else {
            $customer['expire'] = false;
        }

        // put our customer in the cart
        $this->go_cart->save_customer($customer);


        return $customer;
    } else {
        return false;
    }
}
2
What is the question ? - exussum
What are the back tics for? - Mark
A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: controllers/secure.php Line Number: 46 abida Sultana - Ebrahim
Search and delete those back ticks to start. $email should be $email. - cartalot

2 Answers

2
votes

If you did a var_dump on your login variable you will see that it is an array not an object so you can't deal with it like an object.

so go to your model and modify the following:

$customer = $result->row_array();

to be:

$customer['result'] = $result->row_array();

then in line 46 use it as:

$login['result']->last_name;

Why this is happening:

because as you defined $customer as an object at first. you also redefined it later in your model as an array by using $customer['something'] pattern of assignation. So you can't have it your way, it's either an array or an object.

0
votes
 //You used this code because row_array return array not object
 `$`login["result"] = `$`this->Customer_model->login(`$`email, `$`password, `$`remember);
  echo  $login['result']["last_name"];