schoumi26 Posted April 21, 2014 Share Posted April 21, 2014 (edited) Hello, I use prestashop 1.5.6.2 I created a new page that allows my clients to see the history of contest in which they participated. ContestController.php <?php class ContestControllerCore extends FrontController { public $php_self = 'contest'; public $id_contest; public $id_customer; public $date; public $desc; public $typetr; public $statut; public function initContent() { parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'contest.tpl'); } public static $definition = array( 'table' => 'contest', 'primary' => 'id_contest', 'fields' => array( 'id_customer' => array( 'type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true, ), 'date' => array( 'type' => ObjectModel::TYPE_STRING, ), 'typetr' => array( 'type' => ObjectModel::TYPE_STRING, ), 'statut' => array( 'type' => ObjectModel::TYPE_STRING, ), 'desc' => array( 'type' => ObjectModel::TYPE_STRING, 'required' => true, ) ), ); public function displaycontent() { $requete = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'contest` WHERE `id_customer` = \''.pSQL($context->customer->id).'\'')or die(mysql_error()); $this->context->smarty->assign('requete',$requete); $this->setTemplate(_PS_THEME_DIR_.'contest.tpl'); } } Contest.tpl <table id="order-list" class="std"> <thead> <tr> <th class="first_item">{l s='ID'}</th> <th class="columnDate">{l s='Date'}</th> <th class="item">{l s='Type'}</th> <th class="item">{l s='Desc'}</th> <th class="item">{l s='Statut'}</th> </tr> </thead> <tbody> {foreach from=$requete item=trans name=myLoop} <tr> <td class="history">{$trans->id_contest}</td> <td class="history_date bold">{$trans->date}</td> <td class="history">{$trans->typetr}</td> <td class="history">{$trans->desc}</td> <td class="history">{$trans->statut}</td> </tr> {/foreach} </tbody> </table> No results are returned to contest.tpl while there has results in my table. I have the following errors with the debug mode: Notice: Undefined index: requete in Notice: Trying to get property of non-object in Thank you for your help Edited April 21, 2014 by schoumi26 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 variable $requete doesnt exist. make sure that your quere is executed and that this variable contains any content add print_r($requete); or in smarty {$requete|print_r} and check results. Link to comment Share on other sites More sharing options...
schoumi26 Posted April 21, 2014 Author Share Posted April 21, 2014 When I add {$requete| print_r} on my page contest.tpl, it shows me the results of my query. But in my <table>, it returns me in every fields Notice: Trying to get property of non-object in /home/jeconomi/public_html/cache/smarty/compile/40/49/81/404981feda6ea707bc1411f4e9583c35ac063fa9.file.contest.tpl.php on line 71 I do not understand my error Thank you for your help Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 perhaps instead of "object" call you should try with arrays <td class="history">{$trans->id_contest}</td> instead of code above use: <td class="history">{$trans['id_contest']}</td> do the same for each variable Link to comment Share on other sites More sharing options...
schoumi26 Posted April 21, 2014 Author Share Posted April 21, 2014 Thank you very much Vekia it works perfectly Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 you're welcome glad to hear that i could help a little :-) with regards, Milos Link to comment Share on other sites More sharing options...
schoumi26 Posted April 21, 2014 Author Share Posted April 21, 2014 When there is a result, it appears perfectly. When the query returns no results, nothing is displayed. However, I put an if condition. If a result is returned, it is displayed. Else, "You do not have a contest" is displayed. I do have a problem with the condition. Thank you for your help contest.tpl {if $requete && count($requete)} <table id="order-list" class="std"> <thead> <tr> <th class="first_item">{l s='ID'}</th> <th class="columnDate">{l s='Date'}</th> <th class="item">{l s='Type'}</th> <th class="item">{l s='Desc'}</th> <th class="item">{l s='Statut'}</th> </tr> </thead> <tbody> {foreach from=$requete item=trans name=myLoop} <tr> <td class="history_method">{$trans['id_contest']}</td> <td class="history_date bold">{$trans['date']}</td> <td class="history_link bold">{$trans['typetr']}</td> <td class="history_method">{$trans['desc']}</td> <td class="history_state">{$trans['statut']}</td> </tr> {/foreach} </tbody> </table> <div id="block-order-detail" class="hidden"> </div> {else} <p class="warning">{l s='You do not have a contest'}</p> {/if} Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 can you show output of {$requete|var_dump} if there is no result? Link to comment Share on other sites More sharing options...
schoumi26 Posted April 22, 2014 Author Share Posted April 22, 2014 I just try {$requete| var_dump} and he returned me this results in the database. array(1) { [0]=> array(6) { ["id_contest"]=> string(2) "25" ["id_customer"]=> string(1) "7" ["date"]=> string(10) "21/04/2014" ["desc"]=> string(5) "20.00" ["typetr"]=> string(12) "Contest" ["statut"]=> string(36) "Lost" } } Thank you very much Link to comment Share on other sites More sharing options...
vekia Posted April 22, 2014 Share Posted April 22, 2014 as you can see there are results, you said that you've got troubles when there is no result Link to comment Share on other sites More sharing options...
PascalVG Posted April 22, 2014 Share Posted April 22, 2014 What is the exact "problem with the condition " that you bump into? Maybe see if $requete is defined first: if (isset($requete) && !empty($requete) && count($requete) ) pascal. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now