Prestashop Backoffice控制器 - 删除对象时出错(无法加载对象)

时间:2017-06-18 17:44:59

标签: listview controller prestashop

我正在开发一个客户Prestashop模块,经过数周的努力,我设法自己解决了大多数小问题。但是,我无法传递此错误消息:删除对象时出错。 avanto_keys(无法加载对象)

我的模块名称是:avantokey

表格列表的管理员:AdminAvantokeyLogController

当我在行动作按钮上单击“删除”时,会弹出一条错误消息。知道为什么它无法加载对象吗?

    class AdminAvantokeyLogController extends ModuleAdminController
{
    public function __construct()
    {

        $this->bootstrap = true;
        $this->module = 'avantokey'; // valid module name
        $this->table = 'avanto_keys'; // DB table name where your object data stored
        $this->identifier = 'id_avanto_keys';
        $this->fields_list = $this->fieldList();
        $this->actions = array('view', 'edit', 'delete');
        $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->l('Delete selected'),
                'icon' => 'icon-trash',
                'confirm' => $this->l('Delete selected object?')
            )
        );

    parent::__construct();
    }

    public function fieldList()
    {

        $fields_list = array(
            'id_avanto_keys' => array(
                'title' => $this->l('ID Key'),
                'width' => 140,
                'type' => 'text',
            ),
            'id_product' => array(
                'title' => $this->l('Product'),
                'width' => 140,
                'type' => 'text',
            ),
            'serial_key' => array(
                'title' => $this->l('Serial'),
                'width' => 140,
                'type' => 'text',
            ),
        );
        return  $fields_list;
    }

}

2 个答案:

答案 0 :(得分:0)

你有桌面的ObjectModel吗?

您需要在构造函数中指定它。

$this->className = 'myobjectmodel';

答案 1 :(得分:0)

我在另一个Prestashop模块中突然找到了答案。这是你必须删除表格行的方法: 在__constructor方法中添加这个额外的行:

$this->className = "AvantoKeyTest"; // The class name of my object

然后你必须创建一个新的对象类。所以,我创建了一个新文件:' modulename' /classes/test.php

在这个文件中我制作了这个方法:

class AvantoKeyTest extends ObjectModel
{
    /** @var string Name */
    public $user;
    public $comment;
    public $active;
    public $id_leoblog_blog;
    public $date_add;
    public $email;
    public $id_shop;
    /**
     * @see ObjectModel::$definition
     */
    public static $definition = array(
        'table' => 'avanto_keys',
        'primary' => 'id_avanto_keys',
        'fields' => array(
            'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
            'serial_key' => array('type' => self::TYPE_STRING, 'required' => false),
        ),
    );
}