我一直在尝试在PrestaShop中实施Admin标签。我想显示数据库中的记录。对于我想要编辑,更新,删除选项的每条记录。
我的controllers / admin / AdminEblpayment.php文件包含以下代码:
class AdminEblpaymentController extends ModuleAdminController
{
public function __construct()
{
$this->className = 'EblPaymentModel';
$this->table = 'ebl_payments';
$this->identifier = "id";
$this->_defaultOrderBy = 'created_at';
$this->_defaultOrderWay = 'desc';
$this->orderBy = "created_at";
$this->orderWay = "desc";
$this->meta_title = $this->l('EBL payment attempts');
$this->deleted = false;
//$this->explicitSelect = true;
$this->list_no_link = true;
$this->context = Context::getContext();
//$this->lang = true;
$this->bootstrap = true;
$this->sortedTree = array();
if (Shop::isFeatureActive()) {
Shop::addTableAssociation($this->table, array('type' => 'shop'));
}
$this->addRowAction('edit');
$this->addRowAction('details');
$this->addRowAction('updatestatus');
$this->addRowAction('cart');
$this->fields_list = array(
'id' => array(
'title' => $this->l('ID'),
'type' => 'int',
'align' => 'center',
'width' => 25,
),
'cart_id' => array(
'title' => $this->l('Cart id'),
'width' => 'auto',
'orderby' => false
),
'order_id' => array(
'title' => $this->l('Order id'),
'width' => 'auto',
'orderby' => false
),
'status' => array(
'title' => $this->l('Status'),
'width' => 'auto',
'orderby' => false
),
'result' => array(
'title' => $this->l('Result'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'result_code' => array(
'title' => $this->l('Result code'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'dbbl_transaction_id' => array(
'title' => $this->l('Transaction id'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'dbbl_response' => array(
'title' => $this->l('Response'),
'width' => 70,
'align' => 'center',
'orderby' => false
),
'created_at' => array(
'title' => $this->l('Created at'),
'width' => 70,
'align' => 'center',
'orderby' => true
),
'updated_at' => array(
'title' => $this->l('Updated at'),
'width' => 70,
'align' => 'center',
'orderby' => true
)
);
parent::__construct();
}
}

我的模型/ EblpaymentModel.php文件包含以下代码:
class EblPaymentModel extends ObjectModel
{
private $_catTree = array();
public $id;
public $cart_id;
public $order_id;
public $ebl_order_id;
public $ebl_status;
public $ebl_result;
public $ebl_result_code;
public $ebl_card_number;
public $ebl_transaction_id;
public $ebl_request;
public $ebl_response;
public $created_at;
public $updated_at;
//Multilang Fields
public $name;
public $description;
public $meta_description;
public $link_rewrite;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'ebl_payments',
'primary' => 'id',
'multilang' => false,
'fields' => array(
//Fields
'cart_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'order_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'ebl_order_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'ebl_status' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'ebl_result' => array('type' => self::TYPE_INT),
'ebl_result_code' => array('type' => self::TYPE_STRING),
'ebl_card_number' => array('type' => self::TYPE_STRING),
'ebl_transaction_id' => array('type' => self::TYPE_STRING),
'ebl_request' => array('type' => self::TYPE_STRING),
'ebl_response' => array('type' => self::TYPE_STRING),
'created_at' => array('type' => self::TYPE_STRING),
'updated_at' => array('type' => self::TYPE_STRING),
//Multilanguage Fields
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 250),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 250),
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 250),
'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 250),
)
);

在BO下" Eblpayment"选项卡我有以下列表,但我无法编辑,更新,删除。
当我点击编辑链接时,我得到了 - "未找到EblPaymentModel模型"错误:
请有人给我一些详细记录的资源链接,用于开发管理模块"管理员标签","记录列表页面,包含编辑,更新,删除操作"。
提前致谢。
答案 0 :(得分:1)
您需要在此控制器文件的顶部require_once 'path_to_your_model_file'
。
列表渲染不使用模型类,这就是为什么你没有得到任何错误,但View / Edit确实使用它。
您还需要在$this->fields_form
方法中为View / Edit定义__construct()
数组。
查看文档或本机管理员控制器以获得正确的定义。
这样添加了行按钮。
$this->addRowAction('edit');
$this->addRowAction('update');
$this->addRowAction('delete');
$this->addRowAction('whatevernameyouwant');
加载页面或处理某些内容(保存到数据库或其他内容),例如点击' whatevernameyouwant'您使用postProcess()
,processWhatevernameyouwant()
和renderView()
方法。
public function postProcess() {
if (Tools::getIsset('whatevernameyouwant') {
// Set display to 'view' if you want to render some content
// When display is set to 'view' the controller will call renderView() method to display content
$this->display = 'view';
// Set action if you want to process something
// When you set an action the controller will call processWhatevernameyouwant() method
$this->action = 'whatevernameyouwant';
}
return parent::postProcess();
}
public function renderView() {
// return some content related to whatevernameyouwant action
if (Tools::getIsset('whatevernameyouwant') {
return $someTemplateContent;
}
return parent::renderView();
}
public function processWhatevernameyouwant() {
// process some stuff in here
}