如何将sql查询添加到自定义PHP页面?

如何将sql查询添加到自定义PHP页面?,php,mysql,prestashop,prestashop-1.6,Php,Mysql,Prestashop,Prestashop 1.6,我一直在为我的Prestashop网站创建一个简单的博客页面。到目前为止,我已经能够创建以下文件,模板显示正确 BlogController.php(位于/controllers/front目录) 当我尝试在blog.php中运行以下内容时 $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT `id_order` FROM `ps_orders`'); $ord

我一直在为我的Prestashop网站创建一个简单的博客页面。到目前为止,我已经能够创建以下文件,模板显示正确

BlogController.php(位于/controllers/front目录)

当我尝试在blog.php中运行以下内容时

$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
            SELECT `id_order`
            FROM `ps_orders`');

$orders = array();

foreach($results as $result) {
    $orders[] = $result['id_order'];
}

echo $orders;

如果您使用的是Prestashop 1.6,我认为您必须在BlogController.php中使用initContent()而不是displayContent(),如:

public function initContent()
{
    // you can put your sql queries here and uses smarty to send variables to your view blog.tpl
    parent::initContent();
    $this->setTemplate(_PS_THEME_DIR_.'blog.tpl');
}
但是最好使用模块的创建来完成您想要的任务

{capture name=path}{l s='Blog'}{/capture}

<h1>{l s='Blog posts'}</h1>
Notice: Array to string conversion in /home/ystaajux/public_html/blog.php on line 15
Array
Warning: require_once(/home/ystaajux/public_html/controllers/BlogController.php): failed to open stream: No such file or directory in /home/ystaajux/public_html/classes/ControllerFactory.php on line 43
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
            SELECT `id_order`
            FROM `ps_orders`');

$orders = array();

foreach($results as $result) {
    $orders[] = $result['id_order'];
}

echo $orders;
public function initContent()
{
    // you can put your sql queries here and uses smarty to send variables to your view blog.tpl
    parent::initContent();
    $this->setTemplate(_PS_THEME_DIR_.'blog.tpl');
}