Jump to content

Adding PHP code


EssexMedia

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated