Saved all values null in cakephp 3

I am using cake php 3 version. I try to insert data into db but inserting null values. I check so many ways i couldn’t find the issue: This is is my controller code
if ($this->request->is(‘post’)) {

       $expense = $this->Expenses->newEntity();
        $expense = $this->Expenses->patchEntity($expense,$this->request->getData());

           echo "<pre>";print_r($expense); die;

        if ($this->Expenses->save($expense)) {

            

            echo "Save Successfully!";die;

            /*$this->Flash->success(__('The {0} has been saved.', 'Expense'));

            if($jcid > 0)

                 return $this->redirect(['action' => 'view/'.$jcid,'controller' => 'jobcard']);

            return $this->redirect(['action' => 'index']);*/

        }

        else {

        print_r($expense->errors()); die;

        //$this->Flash->error(__('The {0} could not be saved. Please, try again.', 'Expense'));

        //}

        }

    }

Save null filed why?

Are the properties you want to patch accessible?

Are there any errors reported in your entity after patching or after saving?

App\Model\Entity\Expense Object
(
[msinumber] => MSI/20/0001
[msi_index] => 1
[[new]] => 1
[[accessible]] => Array
(
[msinumber] => 1
[msi_index] => 1
)

[[dirty]] => Array
    (
        [msinumber] => 1
        [msi_index] => 1
    )

[[original]] => Array
    (
    )

[[virtual]] => Array
    (
    )

[[hasErrors]] => 
[[errors]] => Array
    (
    )

[[invalid]] => Array
    (
    )

[[repository]] => Expenses

)

Exactly as @dreamingmind suggested. You’ve got it set so that these are the only two fields that can be set by patching.

1 Like

The entity you show does have 2 values patched onto it and they are the only two values you allow (through ‘accessible’). But there is a lot that is unknown here.

  • what type is msinumber? in the entity looks like it might be a string but has no quotes.
  • is this match to the record that made the record image you included in your question? In that msi_index does not exist but `msiindex does.
  • are these two values the only ones you tried to patch?
  • we can assume this entity is ‘after patch’. It shows no validation errors, but are there any validations set for this enitity? If not, it might patch just like this but still fail to save because of some column-type or constraint problem. I’m not 100% sure, but I think the after-save entity might also show errors specific to the save.

Bottom line, there is just too much ambiguity here to say much more about what might be happening.

1 Like

Thank you @dreamingmind and @Zuluru . I will check and let me know