Jump to content

Show database table in custom backoffice module


Recommended Posts

Hello,

I've tried to execute a SELECT statement in my backoffice module to show the result in a html table.

When I look on the backoffice page of the module this error occures:

Notice: Trying to get property of non-object

 

This is my code of the TabController:

<?php
class AdminKonfiguratorTabController extends ModuleAdminController
{
	public function __construct()
	{
		parent::__construct();
	}
	
	public function initContent()
	{
		$category_id = 15;
		$category = new Category($category_id);
		$products = $category->getProducts($this->context->language->id, 0, 0, null, null, false, true, false, 1, true, null, true);
		
		foreach($products as $product) 
		{
			echo '<br>'; var_dump($product);
		}

		$sqlprod = 'SELECT prstshp_product_lang.`name`, prstshp_product_lang.`link_rewrite`, prstshp_product_lang.`id_product`, prstshp_category_product.`id_category`, prstshp_product_shop.`active` FROM `prstshp_product_lang` LEFT JOIN `prstshp_category_product` ON prstshp_product_lang.`id_product`= prstshp_category_product.`id_product` LEFT JOIN `prstshp_product_shop` ON prstshp_product_lang.`id_product`= prstshp_product_shop.`id_product` WHERE `id_lang` = 1 AND `id_category` = 15';		
		
		$prods = Db::getInstance()->ExecuteS($sqlprod);	
		
		$query = 'SELECT * FROM mySQLTable';
		$data = Db::getInstance()->ExecuteS($query);
		
		$this->context->smarty->assign('products', $prods);
		$this->context->smarty->assign('data', $data);
		$this->setTemplate('AdminKonfiguratorTab.tpl');
		return parent::initContent();
	}
	
	public function renderView()
	{
		return parent::renderView();
	}
}	

 

This is the code of the template file

<p>Hello world!</p>
<table>
{foreach $data as $dat}
	<tr>
		<td>{$dat.cartID}</td>
		<td>{$dat.price}</td>
		<td>{$dat.attributeNumber}</td>
		<td>{$dat.id}</td>
	</tr>
{/foreach}
</table>
{foreach $products as $product}
	<p>{$product.id_product}</p>
{/foreach}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...