0

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;
    }
}
4
  • 3
    What is the question ? Commented Sep 28, 2013 at 16:21
  • 2
    What are the back tics for? Commented Sep 28, 2013 at 16:32
  • A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: controllers/secure.php Line Number: 46 abida Sultana Commented Sep 28, 2013 at 17:42
  • Search and delete those back ticks to start. $email should be $email. Commented Sep 28, 2013 at 21:28

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

<pre>echo 'pre> -----<br>'; print_r($login); echo 'abida Sultana'.$login['result']->last_name; exit();
$login = $this->Customer_model->login($email, $password, $remember); echo '<pre> -----<br>'; print_r($login); echo 'abida Sultana'.$login['result']->last_name; exit();
you used to get Message: Trying to get property of non-object which is not the same error. the new error now says Undefined property: stdClass::$last_name. which means the last_name is not being fetched from the database.
@Ebrahim - just make sure that you are getting last_name from your DB
0
 //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"];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.