0

私は次のコントローラーを持っています (supernavigationloggedin):

<?php

class Supernavigationloggedin extends CI_Controller {  
    function index(){
        #get current session id
            $currentSessionID = $this->session->userdata('session_id'); 
        #get all the account row for the given sessionID
            $data['info'] = $this->db->get_where('Client', array('session_id'=>$currentSessionID))->row(); 
        #views
            $this->load->view('supernavigationloggedin',$data);
    } 
}


?>

そして、(supernavigationloggedin) という名前の次のビュー:

<div id="superNavigation">
    <h5><strong>Welcome</strong>, <?php $info->fname; ?>&nbsp;<a href="#">Account Settings</a></h5>
    <div class="clearL"> </div>
</div

>

オンラインでエラーをスローし続けます:<h5><strong>Welcome</strong>, <?php echo $info['fname']; ?>&nbsp;<a href="#">Accountそのメッセージ: >>> Trying to get property of non-object

私は試しました:<?php echo $info['fname']; ?> <?php echo $info->fname; ?> しかし、どちらもうまくいかないようです。

4

1 に答える 1

1

$info  が空であり、データベース要求が行われていないためです。クエリでオブジェクトを返す場合は、次のようにする必要があります。

$data['info'] = $this->db->get_where('Client', array('session_id'=>$currentSessionID))->row();

または、配列に入れたい場合は、次のようにします。

$data['info'] = $this->db->get_where('Client', array('session_id'=>$currentSessionID))->row_array();

このように動作するはずです。row()またはrow_array()クエリを実行するために必要です。

于 2012-11-09T19:43:16.233 に答える