我正在使用 Opencart 版本 2.1.0.1,如何在管理 Controller 中加载前端模型,
我有一个模型函数,它告诉外部预订 ID
class ModelShippingParcelled extends Model {
public function getParcelledBooking($order_id) {
$query = $this->db->query("SELECT booking_id FROM " . DB_PREFIX . "parcelled WHERE order_id = '" . (int)$order_id . "'");
return $query->row;
}
我想在管理 Controller 中加载这个模型。做这个的最好方式是什么?
我也应该在 admin 中重写这个模型吗?但我不想重写相同的函数。如果有好的方法请推荐!
最佳答案
好吧,有一个丑陋的技巧可以实现你想要的。例如,如果您想从您的管理 Controller 使用前端的目录/产品模型,那么您可以:
require_once $_SERVER['DOCUMENT_ROOT'] . "/catalog/model/catalog/product.php";
$product = new ModelCatalogProduct($this->registry);
当您想从前端 Controller 使用管理模型时,这也将起作用,只需更改
require
陈述。
关于opencart - 如何在管理 Controller 中加载目录模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35383861/