0

我在 Codeigniter 框架中面临一个新问题。她是我的输出

大批
(
    [id] => 2
    [名字] => 马鲁夫
    [姓氏] => Ifftekhar
    [蛞蝓] =>
    [电子邮件] => support@russelhost.com
    [电子邮件订阅] => 1
    [自我] =>
    [电话] => 01767820010
    [公司] => 罗素主机
    [default_billing_address] =>
    [default_shipping_address] =>
    [ship_to_bill_address] => 真
    [密码] => 0689d59aa30bdca7207db3d449255650
    [活跃] => 1
    [group_id] => 1
    [已确认] => 0
    [group_discount_formula] => - 0
    [过期] => 1380390903
)
遇到 PHP 错误

严重性:通知

消息:试图获取非对象的属性

文件名:控制器/secure.php

行号:46
阿比达苏丹娜

这是控制器

`$`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(`$`登录);
   echo 'abida Sultana'.`$`login->last_name; --------------------行号:46
   出口();

和模型是

功能登录(`$`电子邮件,`$`密码,`$`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();

    如果(`$`客户){

        // 获取客户地址
        `$`this->db->where(array('customer_id' => `$`customer['id'], 'id' => `$`customer['default_billing_address']));
        `$`address = `$`this->db->get('customers_address_bank')->row_array();
        if (`$`地址) {
            $fields = unserialize($address['field_data']);
            $customer['bill_address'] = $fields;
            $customer['bill_address']['id'] = $address['id']; // 保存地址 id 以供将来参考
        }

        $this->db->where(array('customer_id' => $customer['id'], 'id' => $customer['default_shipping_address']));
        $address = $this->db->get('customers_address_bank')->row_array();
        如果($地址){
            $fields = unserialize($address['field_data']);
            $customer['ship_address'] = $fields;
            $customer['ship_address']['id'] = $address['id'];
        } 别的 {
            $customer['ship_to_bill_address'] = 'true';
        }


        // 设置任意团体折扣
        if ($customer['group_id'] != 0) {
            $group = $this->get_group($customer['group_id']);
            if ($group) { // 组可能不存在
                if ($group->discount_type == "固定") {
                    $customer['group_discount_formula'] = "-" 。$group->折扣;
                } 别的 {
                    $percent = (100 - (float) $group->discount) / 100;
                    $customer['group_discount_formula'] = '* (' . $percent . ')';
                }
            }
        }

        如果(!$记住){
            $customer['expire'] = time() + $this->session_expire;
        } 别的 {
            $customer['expire'] = false;
        }

        // 将我们的客户放入购物车
        $this->go_cart->save_customer($customer);


        返回$客户;
    } 别的 {
        返回假;
    }
}
4

2 回答 2

2

如果你var_dump对你的login变量做了 a ,你会看到它是一个数组而不是一个对象,所以你不能像一个对象一样处理它。

所以去你的模型并修改以下内容:

$customer = $result->row_array();

成为:

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

然后在第 46 行将其用作:

$login['result']->last_name;

为什么会这样:

因为正如您$customer最初定义为对象一样。您稍后还通过使用分配模式在模型中将其重新定义为数组$customer['something']。所以你不能以你的方式拥有它,它要么是一个数组,要么是一个对象。

于 2013-09-29T09:53:09.107 回答
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"];
于 2013-10-01T10:01:30.980 回答