我:
$this->addRow('$this->userRepo->dateTargetedActual', [$teamMember, $date->year, $date->month], $year, 'Stage target', 'target', $teamMember->image);
但它給我的錯誤:
call_user_func_array() expects parameter 1 to be a valid callback, function '$this->userRepo->dateTargetedActual' not found or invalid function name
我如何得到這個工作?
protected function addRow($func, $params, $data, $year, $traderName, $rowName, $type, $image = null) {
$date = Carbon::createFromDate($year, 4, 1);
$total = 0;
$traderName = $traderName.' '.str_replace(' ', '_', strtolower($rowName));
$params[] = $date->month;
for ($i = 1; $i < 13; $i++) {
$result = call_user_func_array($func, $params);
$data['traders'][$traderName]['amounts'][] = $result;
$total += $result;
$date->addMonth();
}
$data['traders'][$traderName]['amounts'][] = $total;
$data['traders'][$traderName]['image'] = $image;
$data['traders'][$traderName]['row_name'] = $rowName;
$data['traders'][$traderName]['row_type'] = $type;
return $data;
}
:
如果
$this->userRepo->dateTargetedActual
擁有一個數據,你需要一個回調函數返回的數據塊,那麼你就可以定義內嵌的函數調用裏面''?另外如果dateTargetedActualy是你想用的函數(),所以我認爲這應該是 $ this-> addRow($ this-> userRepo-> dateTargetedActual(),[$ teamMember,$ date-> year,$ $ year,'Stage target','target',$ teamMember-> image); –'$ this-> userRepo-> dateTargetedActual'的值是什麼?它存儲了一個函數嗎?或者你想讓'addRow()'函數在'$ this-> userRepo'對象上調用'dateTargetedActual()'嗎? – patricus