php - displaying an extra field added to the database in opencart on the order page
问题描述
I have added an extra field to the oc_order table in an Opencart database.
However, when I try and check if it exists or displays the data in that filed, I see nothing.
I have updated the catalogue/view/theme/account/order_info.twig file with the following to test both displaying the new field and using an if statement...
{{ newfield }} {% if newfield == true %}
WORKS
{% else %}
NOT WORKING
{% endif %}
I have a '1' inset in the database but I always get the 'NOT WORKING' displayed.
Any help much appreciated.
解决方案
要从数据库中检索数据并将其显示在您的模板上,您应该首先在相应的控制器文件中从数据库中检索数据
$query = "SELECT newfield FROM " . DB_PREFIX . "table_name ";
比你应该在同一个控制器文件中声明它
if ($query->rows) {
$data['newfield'] = $query->row['newfield'];
} else {
$data['newfield'] = '';
}
现在您可以在模板中检索它
{% if newfield %}
WORKS {{ newfield }}
{% else %}
NOT WORKING
{% endif %}
推荐阅读
- performance - .await 对 Ready 未来的性能影响是什么?
- unity3d - 如何使用 Vuforia 在图像中找到被覆盖的元素?
- node.js - 我如何知道子进程的标准输出数据是否已分解为缓冲区块?
- java - 如何在 Eclipse 中的 Java Build Path 中更新 Android
- powerbi - 如何不在表格中显示空白值
- css - 无法将自定义字体添加到 Rails 应用程序
- git - 推送的本地分支在远程显示为陈旧
- ios - 由于 NSMicrophoneUsageDescription 缺失,Apple 应用审核流程被拒绝
- pdfbox - PDFTextStripper:最后一个字母位于第一个字母之前
- python - CTCI 第 6 版 1.9