我正在开发一个分类帐记录维护应用程序,其中基于某些条件,我正在查询表中的行列表,并将它们存储在一个对象中。目前,这是创建对象的方式:
public function __construct($ledgerData)
{
$AccountModel = new AccountModel();
$this->ledgerRecordDataId = $ledgerData->ledgerRecordDataId;
$this->ledgerId = $ledgerData->ledgerId ;
$temp = $AccountModel->getLedgerDetails($ledgerData->ledgerId );
if (!empty($temp))
$this->ledgerName = $temp[0]->ledgerName;
else
$this->ledgerName = "Nil";
$temp = $AccountModel->getSubLedgerDetails($ledgerData->subLedgerId );
if (!empty($temp))
$this->subLedgerName = $temp[0]->subLedgerName;
else
$this->subLedgerName = "Nil";
$temp = $AccountModel->getLocationDetails($ledgerData->locationId);
if (!empty($temp))
$this->location = $temp[0]->locationName;
else
$this->location = "Nil";
$temp = $AccountModel->getDepartmentDetails($ledgerData->deptId);
if (!empty($temp))
$this->department = $temp[0]->deptName;
else
$this->department = "Nil";
$temp = $AccountModel->getProjectDetails($ledgerData->projectId);
if (!empty($temp))
$this->project = $temp[0]->projectName;
else
$this->project = "Nil";
$this->debitAmount = $ledgerData->debit;
$this->creditAmount = $ledgerData->credit;
}
我想知道是否有更好的方法通过从 ID 收集数据来创建这些对象?我应该调用存储过程吗?
注意:这些对象存储在一个数组中,然后在将它们返回给用户之前对它们进行一系列处理。