rtofvnt Posted October 12, 2015 Share Posted October 12, 2015 Hi, I think I've lost quite a few brain cells ... or maybe not. I can't figure it out or find in in manual. In my template I have nice custom mysql queries that producing nice array of product groups / products. Before 6 I could just do: $this->assign('products',$products); but now it throws an error: all to a member function assign() on a non-object in array $product is ok - I var_dump it ant it's ok. I know something has been changed, but I can't find it. Please - any help ? Thanks - Matt. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 13, 2015 Share Posted October 13, 2015 why don't you use ActionHooks instead to pass this values to Smarty? anyway try to replace "$this->assign();" with "$smarty->assign();" 0 Quote Link to comment Share on other sites More sharing options...
rtofvnt Posted October 13, 2015 Author Share Posted October 13, 2015 Thanks sentq. I think I'm doing something fundamentally wrong anyway. My aim was to create in template on homepage table of product groups and products, so what I did was: duplicated default template and renamed, in header.tpl at the very top added: <code>{include_php file='templates/ultimatehosting/config.php'}</code> where in config.php I initialize new mysqli object and use that to create array of product groups and products which I'm assigning as smarty variable. Then in homepage.tpl I'm looping through and that's it. <code>$smarty->assign(... </code> - not working. I'm not sure if hooks will let me achieve what I'm looking for. On the other note I'm considering actually to not even using this whmcs system at all - I'm paying lease licence every month but updates that don't care about backward compatibility - that's really bad practice. Thanks for looking at it. Cheers 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 13, 2015 Share Posted October 13, 2015 I didn't see your code yet so I'am not able to tell what need to be changed or how! use this ActionHook to pass variables to Smarty, I believe that you will not need to use the {include_php} or $smarty->assign, etc and things will be much clean and easy. 0 Quote Link to comment Share on other sites More sharing options...
rtofvnt Posted October 13, 2015 Author Share Posted October 13, 2015 Thanks for putting little bit of light on the subject, but it created some shadows that bringing more questions: 1. how should I name file with my custom function in /includes/hooks ? 2. how do I see if it actually works ? In /includes/hool/example.php file I created some basic function: function get_all_products() { $product_groups_query = "SELECT g.* FROM tblproductgroups g WHERE g.hidden <>1 ORDER BY g.order ASC"; $groups = full_query($product_groups_query); foreach($groups as $group) { echo '<pre>'; var_dump($group); echo '</pre>'; } } and then within the same file at the bottom: add_hook("ClientAdd",1,"get_all_products"); Cheers - Matt. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 13, 2015 Share Posted October 13, 2015 Matt, with regards to this->, the link below might help... http://docs.whmcs.com/Version_6_Template_Migration_Guide another option would be to write a data feed and use it on the homepage. http://docs.whmcs.com/Data_Feeds it sounds like you already have the php and sql query, so it should just be a case of formatting the output - and would remove the need to pass variables to Smarty. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 13, 2015 Share Posted October 13, 2015 Matt, simply create new file inside /includes/hooks/, with any desired name (productGroups.php) or something and try to put the following code inside: <?php function hook_get_all_products($vars) { $product_groups_query = "SELECT * FROM `tblproductgroups` WHERE `hidden` <>1 ORDER BY `order` ASC"; $groups = full_query($product_groups_query); while (group = mysql_fetch_assoc($groups)){ $grouplist[] = $group; } return array("grouplist" => $grouplist); } add_hook("ClientAreaPage", 1, "hook_get_all_products"); then in template you can loop this information like follow: {foreach item=group from=$grouplist} <b>{$group.name}</b> {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
rtofvnt Posted October 13, 2015 Author Share Posted October 13, 2015 sentq - you are star ! I'm getting there now. Does that mean every hook in /includes/hooks is called ? Also - if I have custom ie. sharedhosting.tpl template file will I be able to access those data from this hook ? Best regards - Matt 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 13, 2015 Share Posted October 13, 2015 Matt, Yes, WHMCS will call all .php files inside /includes/hooks/ directory, and handle the different hook functions when needed. all you have to do is to write a valid hook function/file, and leave the rest for WHMCS. And yes you can access the information from any .TPL files. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 14, 2015 Share Posted October 14, 2015 it's probably also worth mentioning that I think the hooks run in alphabetical order - e.g a.php will run before b.php - but most times that won't matter... unless you know b needs to run before a! 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 14, 2015 Share Posted October 14, 2015 it's probably also worth mentioning that I think the hooks run in alphabetical order - e.g a.php will run before b.php - but most times that won't matter... unless you know b needs to run before a! it should run based on the priority number we specify, right? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 14, 2015 Share Posted October 14, 2015 it should run based on the priority number we specify, right? yes, but if they're the same, then that's when alphabet kicks in. (I don't think i've woken up yet!) 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 14, 2015 Share Posted October 14, 2015 yes, but if they're the same, then that's when alphabet kicks in. (I don't think i've woken up yet!) alphabet! you mean Google? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.