在“事件”类中,我想将“客户”类中的变量“客户名”分配给“类”变量之一。我的类 CustomerTable 有一个名为“getCustomer”的方法,它通过传递一个 customerId 创建一个 Customer 实例。我想从我的 Event 类中调用该方法,以便我可以从该客户那里获取客户名称并将其分配给 Event。
我尝试让 Event 扩展 AbstractActionController 并使用服务管理器来获取该方法,如下面的示例所示。但是,当我尝试在 CustomerTable 类上调用 get() 时,会触发一条消息,指出我正在尝试在非对象上调用 get()。
基本上:有人知道我如何从我的 Event 类中调用 getCustomer() 吗?
我认为的我的事件类:
class Event
{
public $id;
public $CCID;
public $customerName;
public $jobId;
public $timeServer;
public $timeConvert;
public $messageId;
public $message = null;
public $severity;
public $client;
public function exchangeArray($data)
{
$this->id = (isset($data['id'])) ? $data['id'] : null;
$this->CCID = (isset($data['CCID'])) ? $data['CCID'] : null;
// here's the stuff that tries to get the getCustomer() method
$sm = $this->getServiceLocator();
$customer = $sm->get('Admin\Model\CustomerTable')->getCustomer($this->CCID);
$this->customerName = $customer->customerName;
$this->jobId = (isset($data['jobId'])) ? $data['jobId'] : null;
$this->timeServer = (isset($data['TimeServer'])) ? $data['TimeServer'] : null;
$this->messageId = (isset($data['messageId'])) ? $data['messageId'] : null;
$this->severity = (isset($data['Severity'])) ? $data['Severity'] : null;
$this->client = (isset($data['Client'])) ? $data['Client'] : null;
$this->timeConvert = gmdate("H:i", $this->timeServer);
}
}