目前,我正在为我的客户开发自定义忠诚度计划。 我将在单独的标签中显示这些点。 忠诚度计划> (顾客名单)> (查看他们的观点)> (编辑点)
当我点击一个客户时,它将呈现客户点的列表,但是渲染没有问题,但它显示以下错误。
无法加载(或找到)对象
请帮助我克服这个错误。
require_once (_PS_MODULE_DIR_.'\loyaltyprogram\classes\LoyaltyClass.php');
class AdminLoyaltyController extends AdminController
{
public $module;
public function __construct()
{
$this->table = 'loyaltyprogram';
$this->className = 'LoyaltyClass';
$this->module = 'loyaltyprogram';
$this->lang = false;
$this->bootstrap = true;
$this->need_instance = 0;
$this->context = Context::getContext();
$this->fields_list = array(
'id_customer' => array(
'title' => $this->l('Id'),
'width' => 100,
'type' => 'text',
),
'firstname' => array(
'title' => $this->l('First Name'),
'width' => 440,
'type' => 'text'
),
'lastname' => array(
'title' => $this->l('Last Name'),
'width' => 440,
'type' => 'text'
),
'email' => array(
'title' => $this->l('Email'),
'width' => 440,
'type' => 'text'
),
'point' => array(
'title' => $this->l('Point'),
'width' => 440,
'type' => 'text'
)
);
$this->identifier = 'id_customer';
if (!Tools::getValue('id_customer'))
{
$this->_select = 'SUM(a.point) point, b.*';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` b ON b.id_customer=a.id_customer';
}
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?')
)
);
parent::__construct();
}
public function renderList()
{
$this->addRowAction('view');
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function renderView()
{
if (($id = Tools::getValue('id_customer')))
{
// Action for list
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->toolbar_title = 'Loyalty Program > ';
$this->fields_list = array(
'id_loyaltyprogram' => array(
'title' => $this->l('Id'),
'width' => 100,
'type' => 'text',
),
'id_order' => array(
'title' => $this->l('Order Id'),
'width' => 100,
'type' => 'text'
),
'point' => array(
'title' => $this->l('Point'),
'width' => 100,
'type' => 'text'
),
'date' => array(
'title' => $this->l('Date'),
'width' => 200,
'type' => 'text'
)
);
$this->identifier = 'id_loyaltyprogram';
$this->_where = 'AND a.`id_customer` = '.(int)$id;
return parent::renderList();
}
}
}
LoyaltyClass.php
class LoyaltyClass extends ObjectModel
{
/** @var string Name */
public $id_loyaltyprogram;
/** @var integer */
public $id_order;
/** @var integer */
public $point;
public $date;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'loyaltyprogram',
'primary' => 'id_loyaltyprogram',
'multilang' => false,
'fields' => array(
'id_loyaltyprogram' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true),
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true),
'point' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat', 'required' => true),
'date' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true),
),
);
public static function loadLoyaltyProgram()
{
$result = Db::getInstance()->getRow('
SELECT *
FROM `' . _DB_PREFIX_ . 'loyaltyprogram` order_qty
'
);
return new LoyaltyClass($result['id_loyaltyprogram']);
}
}
答案 0 :(得分:0)
renderView()
不需要以下代码$ this-> table =' loyaltyprogram&#39 ;; $ this-> className =' LoyaltyClass&#39 ;; $ this-> module =' loyaltyprogram';
您需要包含类文件:
require_once(目录名(文件强>)' /../../类/ LoyaltyClass.php&#39);
您不需要创建LoyaltyClas的新实例,而是需要调用loadObject()方法,因为它设置了$ this->对象,如:
if(!($ obj = $ this-> loadObject(true))) 返回;
如果你不在renderList()中使用$ obj,你就不必加载它。