Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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()



33.7k
Accepted
answer

This would help:

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


1.3k

Thank you!

This would help:

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