1

この独自の記述モデルをコントローラーにロードできない理由がわかりません。モデルコード:

class Storage extends CI_Model
{

function __construct()
{
    parent::__construct();
    $this->load->database();
}

function getStorageByID( $storageID, $accountID = -1 )
{
    $query = $this->db->select('*')->from('storage')->where('storageID', $storageID);
    if ($accountID != -1)
        $query->where('storageAccountID', $accountID);
    return $this->finishQuery( $query );
}

function getStorageByAccount( $accountID )
{
    $query = $this->db->select('*')->from('storage')->where('storageAccountID', $accountID)->limit( $limit );
    return $this->finishQuery( $query );
}

function finishQuery( $query )
{
    $row = $query->get()->result();  
    return objectToArray($row);
}
}

ロードと実行に使用されるコントローラー内のコード:

$this->load->model('storage'); // Line 147
$storageDetails = $storage->getStorageByAccount( $userData['accountID'] ); // Line 148

エラー:

Message: Undefined variable: storage
Filename: controllers/dashboard.php
Line Number: 148
Fatal error: Call to a member function getStorageByAccount() on a non-object in /home/dev/concept/application/controllers/dashboard.php on line 148

モデル ロード コマンドを var_dump しようとしましたが、NULL しか返されません。

前もって感謝します。

4

2 に答える 2

1

構文は次のとおりです。

$this->load->model('storage');
$storageDetails = $this->storage->getStorageByAccount( $userData['accountID'] );
于 2013-07-02T21:41:07.680 に答える
0

呼び出しているモデルと、コントローラーから呼び出したいモデルの名前を参照する必要があります。この方法で、次のことができます。

 $this->load->model('storage', 'storage');
 $storageDetails = $storage->getStorageByAccount( $userData['accountID'] ); // Line 148

 // but if you wanted you could use your alias to write as followed
 $this->load->model('storage', 'my_storage');
 $storageDetails = $my_storage->getStorageByAccount( $userData['accountID'] ); // Line 148

モデルのロードを機能させるには、ロードしているものを参照してから、ロード先のファイルのコンテキスト内でロードしたものを呼び出しているものを参照する必要があります。幸運を。

于 2013-07-02T21:20:55.630 に答える