【问题标题】:Missing argument 1 for Lib?缺少 Lib 的论点 1?
【发布时间】:2014-06-22 12:49:21
【问题描述】:

我的网站在访问时出错:

缺少 Lib\Repository\Data\TmdbData::getPartTrailer() 的参数 1,在第 2258 行的 /home/*/app/lib/Repository/Data/TmdbData.php 中调用并定义

这是TmdbData.php中的部分代码

 public function getPartnumber()
 {
    if ( ! $this->partnumber) return '';

    return $this->partnumber;
 }

 public function getPartTrailer($parttrailer)
 {
    if ( ! $this->partnumber) return '';

    return $this->partnumber; 
 }

这是第 2258 行:

    'partnumber' => $this->getPartnumber(),

    'parttrailer' => $this->getPartTrailer());  // line 2258

如何解决?非常感谢!

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    你需要给你的函数一个参数。试试:

    'partnumber' => $this->getPartnumber(),
    
    'parttrailer' => getPartTrailer($this);
    

    【讨论】:

    • 您好,它显示错误:调用未定义函数 Lib\Repository\Data\getPartTrailer() 如何解决?谢谢!
    【解决方案2】:

    要么将参数传递给getPartTrailer 方法:

    'parttrailer' => $this->getPartTrailer('someargumant');
    

    或者您可以使用默认参数将参数设为可选:

    public function getPartTrailer($parttrailer = null)
    {
        if ( ! $this->partnumber) return '';
        return $this->partnumber; 
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-04
      • 2011-05-09
      • 2022-08-07
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 2011-08-05
      • 2016-04-05
      相关资源
      最近更新 更多