dq1230123 2017-01-23 10:31
浏览 35

Joomla在null上调用成员函数get()

I have very little php knowledge. I know I'm doing something wrong, but what?

I'm adding the sass compiler from Joomla Master Bootstrap template into my own Joomla template. It works, but not as it should. I can't turn it on or off in the backend. The code in Masterbootstrap is this:

include 'includes/params.php';
if ($params->get('compile_sass', '0') === '1') {
    require_once "includes/sass.php";
}

In my template I don't have params.php, but /functions/tpl-init.php. I added the variable $compile_sass there. My code looks like this:

require_once __DIR__ . '/functions/tpl-init.php';
if ($params->get('compile_sass', '0') === '1') {
    require_once "includes/html/sass.php";
}

Doesn't work. I get the error: Call to a member function get() on null

So I changed this into:

require_once __DIR__ . '/functions/tpl-init.php';
require_once "includes/html/sass.php";

That works, but now the compiler is permanently on.

What should I do to correct this?

  • 写回答

2条回答 默认 最新

  • dongzhe3573 2017-01-24 06:05
    关注

    To get template params from outside the template you need to do this

    Template parameters from outside a template

    $app = JFactory::getApplication('site'); 
    $temp = $app->getTemplate(true); 
    $param = $temp->params->get('compile_sass', '0');
    

    Remember the Masterbootstrap template should be active.

    To get any template param you need to do this

    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query  ->select('params')
            ->from('#__template_styles')
            ->where('`template` = ' . $db->q('masterbootstrap')) // Check Spelling of template
            ->where('client_id = 0'); // client_id = 0 for Site and client_id = 1 for Admin
    $db->setQuery($query);
    $params = json_decode($db->loadResult());
    echo $params->compile_sass; 
    

    Better is to create a similar param in your own template using your templateDetails.xml file rather than depending on the external template.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?