duanganleng0577
2015-10-05 19:17
浏览 50
已采纳

如何在动作钩子中回显PHP变量?

Here's my code:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{

if (!is_null($primarySidebar->getChild('Service Details Actions'))) {

  $primarySidebar->getChild('Service Details Actions')
    ->addChild('Check', array(
        'label' => 'Checker',
        'uri' => 'http://example.com/check/'.print_r($vars['params']['domain']).'-check',
        'order' => '3',
    ));
}

});

I am wanting the uri to link to here (assuming $domain = testdomain.com):

http://example.com/check/testdomain.com-check

Instead, it is showing this right now:

http://example.com/check/1-check

This is the specific line that I guess I'm having trouble with:

'uri' => 'http://example.com/check/'.print_r($vars['params']['domain']).'-check',

What am I doing wrong here?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongningce9075 2015-10-05 19:33
    已采纳

    The call to print_r() is unnecessary. Assuming that the string "testdomain.com" is stored in $vars['params']['domain'], then you simply need to concatenate the variable with the string like this:

    'uri' => 'http://example.com/check/'.$vars['params']['domain'].'-check',
    

    The function print_r() prints readable information about the given variable. Typically it is only used for debugging.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题