FOF30\Model\DataModel::setFieldValue PHP Méthode

setFieldValue() public méthode

Sets the value of a field.
public setFieldValue ( string $name, mixed $value = null ) : void
$name string The name of the field to set
$value mixed The value to set it to
Résultat void
    public function setFieldValue($name, $value = null)
    {
        if (array_key_exists($name, $this->aliasFields)) {
            $name = $this->aliasFields[$name];
        }
        if (array_key_exists($name, $this->knownFields)) {
            $this->recordData[$name] = $value;
        }
    }

Usage Example

Exemple #1
0
 /**
  * @param   DataModel  $model
  * @param   \stdClass  $dataObject
  */
 public function onBeforeUpdate(&$model, &$dataObject)
 {
     // Make sure we're not modifying a locked record
     $userId = $model->getContainer()->platform->getUser()->id;
     $isLocked = $model->isLocked($userId);
     if ($isLocked) {
         return;
     }
     // Handle the modified_on field
     if ($model->hasField('modified_on')) {
         $model->setFieldValue('modified_on', $model->getContainer()->platform->getDate()->toSql(false, $model->getDbo()));
         $modifiedOnField = $model->getFieldAlias('modified_on');
         $dataObject->{$modifiedOnField} = $model->getFieldValue('modified_on');
     }
     // Handle the modified_by field
     if ($model->hasField('modified_by')) {
         $model->setFieldValue('modified_by', $userId);
         $modifiedByField = $model->getFieldAlias('modified_by');
         $dataObject->{$modifiedByField} = $model->getFieldValue('modified_by');
     }
 }
All Usage Examples Of FOF30\Model\DataModel::setFieldValue