首页 > 解决方案 > 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.

标签: phpmysqltwigopencartopencart-3

解决方案


要从数据库中检索数据并将其显示在您的模板上,您应该首先在相应的控制器文件中从数据库中检索数据

$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 %}

推荐阅读