我正在尝试将api调用保存到我的数据库中。但保存到数据库时出现错误
我搜索Google并查看此处。我尝试过提供的代码,但运气不佳。
public function updateCalendarIfNeeded($calendarentrydata)
{
foreach($calendarentrydata as $titan)
{
$summary = $titan->summary;
$id = $titan->id;
$fileurl = $titan['attachments']['0']['fileUrl'];
$startdate = $titan->start->datetime;
$enddate = $titan->end->datetime;
$calendarpullerEntryNew = CalendarEvents::findOne([
'calendar_id' => $id
]);
if (!empty($calendarpullerEntryNew)) {
$calendarEvents = $calendarpullerEntryNew;
}
// now update entry if Calendar info found
$calendarEvents->calendar_id = $id;
$calendarEvents->calendar_summary = $summary;
$calendarEvents->calendar_start = $startdate;
$calendarEvents->calendar_end = $enddate;
$calendarEvents->file_link = $fileurl;
if (empty($calendarEvents->id)) {
$calendarEvents->save();
} else {
$calendarEvents->update();
}
}
return $calendarPullerEntry;
}
我正在获得未定义的方法stdClass :: save()。如果我没有记错的话,我正在使用Yii框架进行保存,而我以前从未使用过它,所以我迷路了
我在我的变量上做了一个var_dump,这里的stdclass是调试stdClass Object ( [calendar_id] => 1hj1o20jc6ucli4st6rk60rfic [calendar_summary] => seeing if php loves me [calendar_start] => [calendar_end] => [file_link] => https://drive.google.com/file/d/1AOPdiXtmz8oNrV2uoSNjLcLso5JdU8CM/view?usp
答案 0 :(得分:0)
每个人都需要烤我。我是地球上最愚蠢的人。我忘了调用将ActiveRecord放到我的代码中的函数
// now update entry if Calendar info found
$calendarEvents = new CalendarEvents();
$calendarEvents->calendar_id = $id;
$calendarEvents->calendar_summary = isset($summary) ? $summary : '';
$calendarEvents->calendar_start = $startdate;
$calendarEvents->calendar_end = $enddate;
$calendarEvents->file_link = $fileurl;
if (empty($calendarEvents->id)) {
$calendarEvents->save();
} else {
$calendarEvents->update();
}
对于我来说,我将调用该函数并删除新的CalendarEntry,但这是我的问题,对于那些在那里浪费时间阅读此大声笑的人