【问题标题】:error while trying to save to databases Call to undefined method stdClass::save()尝试保存到数据库时出错调用未定义的方法 stdClass::save()
【发布时间】:2019-10-20 10:25:39
【问题描述】:

我正在尝试将 api 调用保存到我的数据库中。但我在保存到数据库时遇到错误

我搜索谷歌并看这里。我已经尝试过提供的代码,但运气不佳。

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

【问题讨论】:

    标签: php stdclass crafter-cms


    【解决方案1】:

    这里的每个人都需要烤我。我是这个星球上最愚蠢的人,哈哈。我忘了调用放置 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,但这是我的问题,对于那些浪费时间阅读这篇文章的人,我深表歉意

    【讨论】:

      猜你喜欢
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 2019-02-12
      相关资源
      最近更新 更多