How insert null on save in select field |
10-22-2021, 03:38 AM
(This post was last modified: 10-26-2021, 04:13 AM by includebeer. Edit Reason: Formatting )
Hi sorry for english , this is my select :
PHP Code: <div class='row'> In db table this field must bu NULL , where is the best way to insert null on model->save() ? Now i control if $_POST['id_mezzi'] =='' than $_POST['id_mezzi'] = NULL there is a better solution ?
If you use the Entity class , you can add a set() function to do this. See http://codeigniter.com/user_guide/models...ness-logic
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
In your model, create the following method:
PHP Code: protected function setDefaultIDMezzi(array $data) { You must then configure your model to call this method before each insert (and update if desired) by including these protected variables: PHP Code: protected $beforeInsert = ['setDefaultIDMezzi']; Please review the documentation to make sure you completely understand: https://codeigniter.com/user_guide/model...your-model. |
Welcome Guest, Not a member yet? Register Sign In |