在类'Event'中,我想将类'Customer'中的变量'customername'分配给类'变量之一。我的类CustomerTable有一个名为"getCustomer"的方法,该方法通过传递一个customerId来创建一个Customer实例。我想从我的Event类中调用这个方法,这样我就可以从客户那里获取客户名并将其分配给Event。
我已经尝试让Event扩展AbstractActionController并使用服务管理器来获取方法,如下面的示例所示。但是当我尝试在CustomerTable类上调用get()时,会触发一条消息,说我正在尝试在非对象上调用get()。
基本上:有人知道我如何从我的事件类调用getCustomer()吗?
My Event class as I figure it:
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);
}
}
下面是如何加载类的两个示例:
use 'Admin'Model'CustomerTable; // use namespaces
$sm = new CustomerTable();
$customer = $sm->getCustomer($this->CCID);
或者像
一样$sm = new 'Admin'Model'CustomerTable'Tidy();
$customer = $sm->getCustomer($this->CCID);