0

I have created a function insert on phalcon but when I try to run my API the data cant be insert and I got no error in this code the http route is everything good

public function insertAction()
    {

        $p = $this->request->getJsonRawBody();
       

        // model
        $x = new InvBarangKelompok();

        // set data
        $x = $this->postData($x, $p);

        // validasi data
        if (!$x->validation()) {
            $messages = $x->getMessages();
            $pesan = '';
            foreach ($messages as $message) {
                $pesan .= ' '.$message->getMessage();
            }
            return $this->setJsonRespon('terjadi kesalahan', 1);
        }
        // insert data
        if (!$x->create()) {
            $messages = $x->getMessages();
            $this->dm['error'] = $x->getMessages();
            $pesan = '';
            foreach ($messages as $message) {
                $pesan .= ' '.$message->getMessage();
            }
            return $this->setJsonRespon('terjadi kesalahan', $pesan, 1);
        } else {
            return $this->setJsonRespon(null, null, $x);
        }

    }
2
  • Could you share the code for postData and setJsonRespon?
    – Arthur
    Commented Aug 3, 2022 at 8:21
  • thank u sir i forgot to add postData on my code...
    – Tediace
    Commented Aug 4, 2022 at 9:02

1 Answer 1

0

What version of Phalcon are you using?

If you are using a version 5 release candidate (or final release in the future), the Phalcon dev team switched from returning false for no data found, to returning null for no data found. So if you are using Phalcon 5, your code needs to be changed to test for null to work properly. You could either write it as:

if (empty($x->validation())) {
    :
    :

Or whatever you prefer as you favorite PHP method for testing for null (is_null, "=== null", etc.).

Hope that helps a little.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.