We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Help,afterCreate doesn't work

There are two Mysql(5.1.73) tables, tableA and tableB. I want to insert three records into tableB when I have insert a record into tableA.So I used afterCreate method

    public function afterCreate()
    {
        $info = json_decode($this->getInfo(),true);
        foreach ($info as $key => $val) {
            $log = new BdLogs();
            $log->setBdLotteryId($this->getId());
            $log->setCode($this->getCode());
            $log->setMode($val['mode']);
            $log->setWeis($val['weis']);
            $log->setMark($val['mark']);
            $log->setMoney($val['money']);

            $tmp = explode('_', $val['account']);
            $log->setAccount($tmp[1]);
            $log->setBdSiteId($tmp[2]);
            $log->setBdClentId($tmp[3]);

            $log->setBdUserId($this->getBdUserId());
            $log->setCreated(date('Y-m-d H:i:s'));
            $log->setDetail($val);
            $log->setStatus(0);
            //print_r($log->toArray()); it is right!!!
            try {
                $log->save();
            } catch (Exception $e) {
                throw new Exception($e->getMessage());
            }
        }
    }

But it doesn't work and doesn't have Exception,I don't know why? i use Phalcon 1.3

Please help me, Thanks!

It's solved!!! because the field created's type is time(),but I give datetime()



34.6k
Accepted
answer

This would help:

if ($log->save() === false) {
    foreach ($log->getMessages() as $message) {
       echo $message->getMessage();
    }
}


2.3k

Thank you!

This would help:

if ($log->save() === false) {
   foreach ($log->getMessages() as $message) {
     echo $message->getMessage();
  }
}