src/Controller/Component/AppComponent.php
public function toggleField(Table $table, $id, $value, $field = 'status')
    {
        $this->checkIsAjax();
        $this->_checkToggleData($id, $value);

        $this->_controller->viewBuilder()
            ->setLayout('ajax')
            ->setTemplate('toggle')
            ->setTemplatePath('Common');

        $entity = $table->get($id);
        $entity->set($field, !(int) $value);

        if ($result = $table->save($entity)) {
            $this->_controller->set('entity', $result);
            $this->_controller->render('toggle');
        } else {
            throw new \RuntimeException(__d('core', 'Failed toggling field {0} to {1}', $field, $entity->get($field)));
        }
    }
public function toggleField(Table $table, $id, $value, $field = 'status')
    {
        $this->checkIsAjax();
        $this->_checkToggleData($id, $value);

        $this->_controller->viewBuilder()
            ->setLayout('ajax')
            ->setTemplate('toggle')
            ->setTemplatePath('Common');

        $entity = $table->get($id);
        $entity->set($field, !(int) $value);

        if ($result = $table->save($entity)) {
            $this->_controller->set('entity', $result);
            $this->_controller->render('toggle');
        } else {
            throw new \RuntimeException(__d('core', 'Failed toggling field {0} to {1}', $field, $entity->get($field)));
        }
    }
public function toggleField ( Table $ table , $ id , $ value , $ field = 'status' ) { $ this -> checkIsAjax ( ) ; $ this -> _checkToggleData ( $ id , $ value ) ; $ this -> _controller -> viewBuilder ( ) -> setLayout ( 'ajax' ) -> setTemplate ( 'toggle' ) -> setTemplatePath ( 'Common' ) ; $ entity = $ table -> get ( $ id ) ; $ entity -> set ( $ field , ! ( int ) $ value ) ; if ( $ result = $ table -> save ( $ entity ) ) { $ this -> _controller -> set ( 'entity' , $ result ) ; $ this -> _controller -> render ( 'toggle' ) ; } else { throw new \ RuntimeException ( __d ( 'core' , 'Failed toggling field {0} to {1}' , $ field , $ entity -> get ( $ field ) ) ) ; } }
Toggle table field value.

@param   Table $table
@param   int $id
@param   string|int $value
@param   string $field

@throws  \RuntimeException
@throws  \Aura\Intl\Exception
Toggle table field value .