update() публичный Метод

returns success (bool)
public update ( &$in )
Пример #1
0
 $validator->addData('field_name', 'Other', false);
 $validator->addData('field_prompt', 'Other', false);
 $validator->addData('field_required', 'matchRegex', false, '!^(on|off)$!');
 $validator->addData('field_active', 'matchRegex', false, '!^(on|off)$!');
 if ($result = $validator->checkData()) {
     // __ FORM IS VALID
     // TODO -> Which below logic is better? the computed diff, or send all fields for update?
     /*
     // make a difference between updated & original field
     $update = array_diff_assoc(Pommo_Fields::makeDB($_POST),$field);
     // restore the ID
     $update['id'] = $field['id'];
     */
     // let MySQL do the difference processing
     $update = Pommo_Fields::makeDB($_POST);
     if (!Pommo_Fields::update($update)) {
         $json->fail('error updating field');
     }
     $json->add('callbackFunction', 'updateField');
     $json->add('callbackParams', $update);
     $json->success(Pommo::_T('Settings updated.'));
 } else {
     // __ FORM NOT VALID
     $fieldErrors = array();
     $errors = $validator->getErrors();
     foreach ($errors as $key => $val) {
         $fieldErrors[] = array('field' => $key, 'message' => $val);
     }
     $json->add('fieldErrors', $fieldErrors);
     $json->fail(Pommo::_T('Please review and correct errors with your submission.'));
 }