Object 无法加载(或找到)对象的预设置
目前,我正在为我的客户开发定制忠诚度计划。 我将在单独的选项卡中显示这些点,如下所示。 忠诚度计划>客户列表>查看他们的积分>编辑积分 当我单击一个客户时,它将呈现客户点列表,但呈现没有问题,但它显示以下错误 无法加载或找到该对象 请帮我克服这个错误Object 无法加载(或找到)对象的预设置,object,prestashop,Object,Prestashop,目前,我正在为我的客户开发定制忠诚度计划。 我将在单独的选项卡中显示这些点,如下所示。 忠诚度计划>客户列表>查看他们的积分>编辑积分 当我单击一个客户时,它将呈现客户点列表,但呈现没有问题,但它显示以下错误 无法加载或找到该对象 请帮我克服这个错误 require_once (_PS_MODULE_DIR_.'\loyaltyprogram\classes\LoyaltyClass.php'); class AdminLoyaltyController extends AdminControl
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
renderView不需要以下代码
$this->table='loyaltyprogram';
$this->className='LoyaltyClass';
$this->module='loyaltyprogram'
您需要包括类文件,如:
需要_oncedirnameFILE'/../../classes/LoyaltyClass.php'
您需要调用loadObject方法,而不是创建一个新的LoyaltyClas实例,因为它将$this->object设置为:
如果$obj=$this->loadObjecttrue
返回
如果在renderList中不使用$obj,则不必加载它
类文件的名称和位置如何?类文件名为loyaltyclass.php,其位于我的模块类folderHi中,正如您所说,我将我的类包括在我的忠诚度控制器中,但我仍然面临错误。请检查上面修改的代码和类。
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']);
}
}