Jump to content

Problem with using PHP Tags on WHMCS 7.4


Desperadouz

Recommended Posts

Hello,

i was using WHMCS 6.x , i have a module that use PHP Tags on TPL Files.

when i upgraded from WHMCS 5 to WHMCS 6 I did this jobs :

 

enable "Allow Smarty PHP Tags" under Setup > General Settings > Other tab and change the applicable code using our instructions at http://docs.whmcs.com/Version_6_Template_Migration_Guide#.7Bphp.7D_Block_Syntax

 

and module was working.

 

but after upgrading to WHMCS 7.4 now pages that includes PHP Tags show error like this :

 

exception 'Whoops\Exception\ErrorException' with message 'Call to a member function getVariable() on null' in /home/usernsme/public_html/client/templates_c/e61033bc7b84f64ca1bfa51547087b1c13bd2c24_0.file.filename.tpl.php:24
Stack trace:

0 /home/username/public_html/client/vendor/whmcs/whmcs-foundation/lib/Utility/Error/Run.php(0): WHMCS\Utility\Error\Run->handleError(1, 'Call to a membe...', '/home/username/...', 24)

can you help me tofix this problem ?

 

Best regards,

Link to comment
Share on other sites

to be honest, i'm not really seeing anything in those {php} tags that you couldn't do with just Smarty...

so let's take your use of sprintf in the templates inside {php}..

{php}echo sprintf($template->getVariable('_lang')->value['point_tab_title'],$template->getVariable('_lang')->value['hostingaccount']);{/php}

you can use sprintf directly in Smarty as a PHP modifier... so as an example, i'll create two new language strings...

$_LANG['brian_string'] = 'There are %s letters in the alphabet';
$_LANG['brian_letters'] = '26';

in the template, if we just output the first string {$LANG.brian_string}, we will see...

Quote

There are %s letters in the alphabet

but if we use sprintf to use the value of one string in the other...

{$LANG.brian_string|sprintf:$LANG.brian_letters} 
Quote

There are 26 letters in the alphabet

so going back to your code, I suspect that...

{php}echo sprintf($template->getVariable('_lang')->value['point_tab_title'],$template->getVariable('_lang')->value['hostingaccount']);{/php}

could be changed to...

{$LANG.point_tab_title|sprintf:$LANG.hostingaccount}

though it's difficult to know for sure without seeing the actual language strings.

you could always add {debug} to the end of a template if you need to know what Smarty variables are available in the template - but generally the code just seems to be using PHP to access the Smarty variables.. which is a long-winded way to do it.

as a general rule, in v6, and much more in v7, if you see {php} tags, you need to ask yourself whether you need to use them.... in virtually all circumstances, the answer should be no... and you should remember that {php} tags were deprecated and are only "temporarily" being added by WHMCS... whether they will still do that in v8, I doubt - so it's probably best to move away from using them as soon as you can.

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