Backend\Core\Engine\Model::updateExtra PHP Method

updateExtra() public static method

Update extra
public static updateExtra ( integer $id, string $key, string $value )
$id integer The id for the extra.
$key string The key you want to update.
$value string The new value.
    public static function updateExtra($id, $key, $value)
    {
        // recast key
        $key = (string) $key;
        // define allowed keys
        $allowedKeys = array('label', 'action', 'data', 'hidden', 'sequence');
        // key is not allowed
        if (!in_array((string) $key, $allowedKeys)) {
            throw new Exception('The key ' . $key . ' can\'t be updated.');
        }
        // key is 'data' and value is not serialized
        if ($key === 'data' && is_array($value)) {
            // serialize value
            $value = serialize($value);
        }
        $item = array();
        $item[(string) $key] = (string) $value;
        self::getContainer()->get('database')->update('modules_extras', $item, 'id = ?', array((int) $id));
    }

Usage Example

 /**
  * Insert an item in the database
  *
  * @param array $item
  * @return int
  */
 public static function insert(array $item)
 {
     $item['created_on'] = BackendModel::getUTCDate();
     $item['edited_on'] = BackendModel::getUTCDate();
     $db = BackendModel::get('database');
     // insert extra
     $item['extra_id'] = BackendModel::insertExtra('widget', 'Instagram', 'InstagramFeed');
     $item['id'] = (int) $db->insert('instagram_users', $item);
     // update extra (item id is now known)
     BackendModel::updateExtra($item['extra_id'], 'data', array('id' => $item['id'], 'extra_label' => \SpoonFilter::ucfirst(Language::lbl('Instagram', 'InstagramFeed')) . ': ' . $item['username'], 'edit_url' => BackendModel::createURLForAction('Edit', 'Instagram', null) . '&id=' . $item['id']));
     return $item['id'];
 }
All Usage Examples Of Backend\Core\Engine\Model::updateExtra