EssexMedia Posted December 16, 2011 Share Posted December 16, 2011 Hi all, I'm a bit confused as to where I should be putting any additional PHP code? The WHMCS docs for customising the client-side templates give examples of adding php code to tpl's using the curly brackets, it gives this code as one example... {php} $userid = $this->_tpl_vars['userid']; $result = mysql_query("SELECT firstname FROM tblclients WHERE id=$userid"); $data = mysql_fetch_array($result); $firstname = $data["firstname"]; echo $firstname; {/php} But the Smarty template docs say that it's better to put this sort of code into the .php file and not the tpl. Would there be any advantage to having this sort of code in the .php file instead of the tpl file? - I guess that because the php files are in the root whmcs directory and not the template directory there would be a problem with the .php being overwritten on an upgrade - is this the reason that the whmcs docs say to do it in the tpl? Any comments appreciated Mark. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted December 16, 2011 Share Posted December 16, 2011 You can't put PHP code in (most of) the PHP files. They are encoded. You must add the PHP functions to the template, or you can add it as action hooks depending on what you're trying to do. http://docs.whmcs.com/Hooks 0 Quote Link to comment Share on other sites More sharing options...
EssexMedia Posted December 16, 2011 Author Share Posted December 16, 2011 Oh, sorry Laszlof, I mean the php & tpl files that we create ourselves when adding pages to whmcs. -Incidentally, is there a way we can have our own php files encoded like the native whmcs ones? 0 Quote Link to comment Share on other sites More sharing options...
luxwhm Posted December 16, 2011 Share Posted December 16, 2011 Oh, sorry Laszlof, I mean the php & tpl files that we create ourselves when adding pages to whmcs. More details are available at docs.whmcs.com/Creating_Pages -Incidentally, is there a way we can have our own php files encoded like the native whmcs ones? You can use the ioncube's online encoder to encrypt your own php files. Low cost option, 50 cents per php file. To have extra security, we use this encoder to encrypt the configuration.php 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted December 16, 2011 Share Posted December 16, 2011 if they're custom pages, you can do all the PHP processing on the page itself, rather than the templates. This just makes things cleaner. If you want to pass stuff over to the template, assuming you're using these docs: http://docs.whmcs.com/Creating_Pages. You can just use something like this: $smartyvalues['myvar'] = $myvar; You can encode files using ioncube encoder. The online version is fairly inexpensive if you're just doing a few files. The full fledged encoder is about $200 I think. More info at http://www.ioncube.com/ 0 Quote Link to comment Share on other sites More sharing options...
EssexMedia Posted December 17, 2011 Author Share Posted December 17, 2011 Thanks for the info guys, I've been reading through some of the smarty documentation and I can really see the advantages of separating the logic from the layout so I want to use the same method for my own pages. -I know the same separation can be acheived with just php, (without Smarty), but I think you need to be very good at php to do this ...and I'm not - yet I'll definitely check out the ioncube encoder - it does seem to add an extra level of security. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted December 17, 2011 Share Posted December 17, 2011 Its not really about skill level, its not difficult to print html output. Its more for just keeping the code clean, and keeping PHP and HTML separate. $myvar = 'Hello World'; print ' <html> <head> <title>'.$myvar.'</title> </head> <body> <strong>'.$myvar.'</strong> </body> </html>'; 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.