prestashop - Prestashop 1.6,我的课在其他模块中不起作用
问题描述
我创建了一个模块,模块中的一个类扩展到 ObjectModel :模块名称:
<?php
if (!defined('_PS_VERSION_'))
exit;
class StoreOrder extends ObjectModel
{
public $id_store_order;
public $id_customer;
public $nature_piece;
public $client_code;
public $internal_reference;
public $store_code;
public $store_name;
public $ticket_date;
public $custumer_name;
public $ticket_number;
public $product_number;
public $total_ht;
public $total_ttc;
public $payment_mode;
public static $definition = array(
'table' => 'ps_store_order',
'primary' => 'id_store_order',
'fields' => array(
'id_store_order' => array('type' => self::TYPE_INT),
'id_customer' => array('type' => self::TYPE_INT),
'store_code' => array('type' => self::TYPE_STRING),
'store_name' => array('type' => self::TYPE_STRING),
'ticket_date' => array('type' => self::TYPE_STRING),
'ticket_number' => array('type' => self::TYPE_STRING),
'product_number' => array('type' => self::TYPE_STRING),
'total_ht' => array('type' => self::TYPE_STRING),
'total_ttc' => array('type' => self::TYPE_STRING),
'payment_mode' => array('type' => self::TYPE_STRING),
)
);
public function __construct()
{
parent::__construct();
}
public static function getByIdCustomer($id_customer) {
$sql = "SELECT * FROM `ps_store_order` WHERE `id_customer` = ".$id_customer;
$result = Db::getInstance()->executeS($sql);
return $result;
}
}
但是如果我在其他模块中包含这个类来使用它,它在步骤“_PS_VERSION_”的阻塞没有定义,并且我删除了它什么都不返回的条件(代码是股票我不知道为什么)
谢谢..
解决方案
- 您不应检查对象模型上的“_PS_VERSION_”
- 您不应在对象模型上的表名中添加“ps_”前缀:
'table' => 'store_order',
尝试这个:
include_once _PS_MODULE_DIR_ . 'path-to-your-model';
dd(StoreOrder::getByIdCustomer(2));
还建议对 "$id_customer" 使用 (int) :
$sql = "SELECT * FROM `ps_store_order` WHERE `id_customer` = " . (int)$id_customer;
推荐阅读
- sql - SQL如何用有效的查询替换许多“IF”
- c++ - 在 C++17 / C++20 中从 wstring 转换为 u16string 并返回(标准符合)
- python - 如何获取查询集并为每个对象获取查询集
- javascript - 如何在表格中显示随机图像
- python - 如何将 random.choice 转换为整数进行实验?
- java - Spring Data @Query 使用 VARCHAR 而不是 NVARCHAR
- javascript - 为什么我得到 req.next 不是函数错误?
- node.js - Google App Engine 随机自动重启
- flutter - 如何在flutter中从Stripe信用卡获取tokenID
- java - 如何使用 Android 导航组件在某些片段中隐藏操作栏?