V
V
Vladislav Olegovich2019-05-03 13:54:22
PHP
Vladislav Olegovich, 2019-05-03 13:54:22

How to simplify the given RedBeanPHP code?

This code takes data from the form and saves it to the database through a bean in RedBeanPHP. The input names match the bean elements (and hence the fields in the database table).

$GLOBALS['employee']->first_name = $_POST['main']['first_name'];
      $GLOBALS['employee']->last_name = $_POST['main']['last_name'];
      $GLOBALS['employee']->patronymic = $_POST['main']['patronymic'];
      R::store( $GLOBALS['employee']);

Can it be made easier? It’s just that if I have 50 fields in the form, or there will be a lot of forms, for example, then manually prescribe all this, the work is not productive.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kafkiansky, 2019-06-19
@mad_maximus

You create an entity, write all the properties in it by the names of the table fields, create a magic setter, accept the post array, run through the loop, get the data that came in, set it, save it. Of course, between all this you do checks for null.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question