Bolt\Legacy\Storage::updateSingleValue PHP Метод

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

It is called in list of contents.
public updateSingleValue ( string $contenttype, integer $id, string $field, mixed $value ) : boolean
$contenttype string Content Type to be edited.
$id integer Id of content to be updated.
$field string Field name of content to be changed.
$value mixed New value to be defined on field.
Результат boolean Returns true when update is done or false if not.
    public function updateSingleValue($contenttype, $id, $field, $value)
    {
        $id = intval($id);
        if (!$this->isValidColumn($field, $contenttype)) {
            $error = Trans::__('contenttypes.generic.invalid-field', ['%field%' => $field, '%contenttype%' => $contenttype]);
            $this->app['logger.flash']->danger($error);
            return false;
        }
        $content = $this->getContent("{$contenttype}/{$id}");
        $content->setValue($field, $value);
        $comment = Trans::__('The field %field% has been changed to "%newValue%"', ['%field%' => $field, '%newValue%' => $value]);
        $result = $this->saveContent($content, $comment);
        return $result;
    }

Usage Example

Пример #1
0
 public function testUpdateSingleValue()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $storage = new Storage($app);
     $fetch1 = $storage->getContent('showcases/2');
     $this->assertEquals(1, $fetch1->get('ownerid'));
     $result = $storage->updateSingleValue('showcases', 2, 'ownerid', '10');
     $this->assertEquals(2, $result);
     $fetch2 = $storage->getContent('showcases/2');
     $this->assertEquals('10', $fetch2->get('ownerid'));
     // Test invalid column fails
     $shouldError = $storage->updateSingleValue('showcases', 2, 'nonexistent', '10');
     $this->assertFalse($shouldError);
 }