我在我的项目管理系统中使用sonata管理包,我试图让类对象获取如下数据:
$this->getSubject()->getName();
然而,出来的是:
FatalErrorException: Error: Call to a member function getName() on a non-object in MyAdmin.php line 169
任何人都知道什么是错的?欣赏!
已更新 21/09/2014 以下是我要做的事情:
public function getExportFields() {
$this->getSubject()->getPurchasePerItem; //Here return error!
return [
$this->getTranslator()->trans('Order Number') => 'id',
$this->getTranslator()->trans('First Name') => 'customer.First_name',
$this->getTranslator()->trans('Last Name') => 'customer.Last_name',
$this->getTranslator()->trans('Contact') => 'customer.contact',
$this->getTranslator()->trans('Email') => 'customer.email',
$this->getTranslator()->trans('Street') => 'customer.street',
$this->getTranslator()->trans('Town') => 'customer.town',
$this->getTranslator()->trans('State') => 'customer.state',
$this->getTranslator()->trans('Postcode') => 'customer.postcode',
//items may more than one
$this->getTranslator()->trans('Item') => 'purchasePerItem[0].product.model',
$this->getTranslator()->trans('Item_Qty') => 'purchasePerItem[0].quantity',
$this->getTranslator()->trans('Item_price') => 'purchasePerItem[0].product.price',
$this->getTranslator()->trans('Total') => 'total_amount',
$this->getTranslator()->trans('Shipping') => 'delivery_fee',
$this->getTranslator()->trans('Order time') => 'createdAt',
$this->getTranslator()->trans('Last Update') => 'updatedAt',
];