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

CreatBuilder does not automatically call getters methods

Hello,

class Targets extends Model
{

    private $uploaded_at;

    /**
     * @return mixed
     */
    public function getUploadedAt()
    {
        return strtotime($this->uploaded_at);
    }

    /**
     * @param mixed $uploaded_at
     */
    public function setUploadedAt($uploaded_at): void
    {
        $this->uploaded_at = date("Y-m-d H:i:s", $uploaded_at);
    }

}
$rows = $this->modelsManager->createBuilder()
            ->from(['Targets' => '\Admin\Model\Targets'])
            ->getQuery()
            ->execute();

        /* @var \Admin\Model\Targets[] $targets */
        $targets = [];
        foreach ($rows as $row) {
            $targets[] = $row;
        }

        $response = new \Phalcon\Http\Response();
        $response->setJsonContent([
            "data" => $targets
        ]);
        return $response;

The response is

{"data":[{"uploaded_at":"2018-11-18 15:01:00"}]}

but I want to see timestamp (number) here

Could you tell me how I can make these methods (getters) automatically called with $this->modelsManager->createBuilder().

you have to overload toArray method