ghost4life Posted December 29, 2014 Share Posted December 29, 2014 (edited) Hi, I've creadted a new controller, for a new page. I need to get on the tpl the messages from the client but grouped by Token... so I did (I get an old function that I changed for my needs) <?php class ServiceClientController extends FrontController { public $auth = true; // Utile si vous souhaitez que l'utilisateur qui visite cette page soit authentifier public $php_self = 'service-client'; public $authRedirection = 'service-client'; public $ssl = true; public static function getMessagesByIdCustommer($private = true) { $id_custommer = (int) $this->context->cookie->id_customer; return Db::getInstance()->executeS(' SELECT cm.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname, (COUNT(cm.id_customer_message) = 0 AND ct.id_customer != 0) AS is_new_for_me FROM `' . _DB_PREFIX_ . 'customer_message` cm LEFT JOIN `' . _DB_PREFIX_ . 'customer_thread` ct ON ct.`id_customer_thread` = cm.`id_customer_thread` LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON ct.`id_customer` = c.`id_customer` LEFT OUTER JOIN `' . _DB_PREFIX_ . 'employee` e ON e.`id_employee` = cm.`id_employee` WHERE ct.id_custommer = ' . (int) $id_custommer . ' ' . (!$private ? 'AND cm.`private` = 0' : '') . ' GROUP BY cm.token ORDER BY cm.date_add DESC '); } public function initContent() { parent::initContent(); $this->context->smarty->assign(array( 'messages' => getMessagesByIdCustommer(false), )); $this->setTemplate(_PS_THEME_DIR_ . 'service-detail.tpl'); } } The trouble I have is that I don't know how to call this function from my controller to the tpl. I need to do a loop for displaying all threads. Anykind of help will be much appreciate. Edited December 29, 2014 by ghost4life (see edit history) Link to comment Share on other sites More sharing options...
prestarocket Posted December 29, 2014 Share Posted December 29, 2014 Hello, In your tpl, you have access to messages var.You have to make a loop in your tpl like foreach messages as message.. Link to comment Share on other sites More sharing options...
ghost4life Posted December 31, 2014 Author Share Posted December 31, 2014 hi, thanks for your reply, i've tried to do a loop with the var message, but I do have an error ( ! ) Notice: Undefined index: messages in C:\wamp\www\beast\cache\smarty\compile\77\83\91\7783911f07df21f93d564de8226ebfb3aea02c56.file.service-client.tpl.php on line 68 Sorry for my poor english. Cordialement, Stan P. Link to comment Share on other sites More sharing options...
ghost4life Posted January 11, 2015 Author Share Posted January 11, 2015 I've tried like that but it does not work Anykind of help will be much appreciated. public function initContent() { parent::initContent(); $id_customer = $this->context->customer->id; $query = "SELECT * FROM `beast_customer_thread` WHERE `id_customer` = '{$id_customer}' GROUP BY `token`"; $messages = mysql_query($query); $this->setTemplate(_PS_THEME_DIR_ . 'service-client.tpl'); } Link to comment Share on other sites More sharing options...
ghost4life Posted January 12, 2015 Author Share Posted January 12, 2015 I've tried like that also but with no success public function initContent() { parent::initContent(); $id_customer = $this->context->customer->id; $sql = new DbQuery(); $sql->select('*'); $sql->from('customer_thread'); $sql->where('`id_customer` = '.$id_customer); $sql->orderBy('token'); return Db::getInstance()->executeS($sql); $this->setTemplate(_PS_THEME_DIR_ . 'service-client.tpl'); } Link to comment Share on other sites More sharing options...
vekia Posted January 12, 2015 Share Posted January 12, 2015 what you mean by "no success" ? you see some error? btw. return Db::getInstance()->executeS($sql); $this->setTemplate(_PS_THEME_DIR_ . 'service-client.tpl');\ everything after "return" will not be executed. Link to comment Share on other sites More sharing options...
ghost4life Posted January 12, 2015 Author Share Posted January 12, 2015 I did in my tpl $message = mysql_fetch_assoc($result) in a loop, but it says that the var is undefined. In fact I want to get the result from the sql request. Link to comment Share on other sites More sharing options...
ghost4life Posted January 26, 2015 Author Share Posted January 26, 2015 anyone has the answer ? Link to comment Share on other sites More sharing options...
ghost4life Posted February 8, 2015 Author Share Posted February 8, 2015 up! 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