src/Controller/CrudController.php
public function putRemap($sMethod)
    {
        //  Test that there's not an explicit method defined for this action
        $oUri    = Factory::service('Uri');
        $sMethod = 'put' . ucfirst($oUri->segment(4));
        if (method_exists($this, $sMethod)) {
            return $this->$sMethod();
        }

        // --------------------------------------------------------------------------

        $oItem = $this->lookUpResource();
        if (!$oItem) {
            throw new ApiException('Resource not found', 404);
        }

        $this->userCan(static::ACTION_UPDATE, $oItem);

        $oHttpCodes = Factory::service('HttpCodes');

        //  Read from php:://input as using PUT; expecting a JSONobject as the payload
        $sData = stream_get_contents(fopen('php://input', 'r'));
        $aData = json_decode($sData, JSON_OBJECT_AS_ARRAY) ?: [];
        $aData = $this->validateUserInput($aData, $oItem);

        if (!$this->oModel->update($oItem->id, $aData)) {
            throw new ApiException(
                'Failed to update resource. ' . $this->oModel->lastError(),
                $oHttpCodes::STATUS_INTERNAL_SERVER_ERROR
            );
        }

        return Factory::factory('ApiResponse', 'nails/module-api');
    }
public function putRemap($sMethod)
    {
        //  Test that there's not an explicit method defined for this action
        $oUri    = Factory::service('Uri');
        $sMethod = 'put' . ucfirst($oUri->segment(4));
        if (method_exists($this, $sMethod)) {
            return $this->$sMethod();
        }

        // --------------------------------------------------------------------------

        $oItem = $this->lookUpResource();
        if (!$oItem) {
            throw new ApiException('Resource not found', 404);
        }

        $this->userCan(static::ACTION_UPDATE, $oItem);

        $oHttpCodes = Factory::service('HttpCodes');

        //  Read from php:://input as using PUT; expecting a JSONobject as the payload
        $sData = stream_get_contents(fopen('php://input', 'r'));
        $aData = json_decode($sData, JSON_OBJECT_AS_ARRAY) ?: [];
        $aData = $this->validateUserInput($aData, $oItem);

        if (!$this->oModel->update($oItem->id, $aData)) {
            throw new ApiException(
                'Failed to update resource. ' . $this->oModel->lastError(),
                $oHttpCodes::STATUS_INTERNAL_SERVER_ERROR
            );
        }

        return Factory::factory('ApiResponse', 'nails/module-api');
    }
public function putRemap ( $ sMethod ) { //  Test that there's not an explicit method defined for this action $ oUri = Factory :: service ( 'Uri' ) ; $ sMethod = 'put' . ucfirst ( $ oUri -> segment ( 4 ) ) ; if ( method_exists ( $ this , $ sMethod ) ) { return $ this -> $ sMethod ( ) ; } // -------------------------------------------------------------------------- $ oItem = $ this -> lookUpResource ( ) ; if ( ! $ oItem ) { throw new ApiException ( 'Resource not found' , 404 ) ; } $ this -> userCan ( static :: ACTION_UPDATE , $ oItem ) ; $ oHttpCodes = Factory :: service ( 'HttpCodes' ) ; //  Read from php:://input as using PUT; expecting a JSONobject as the payload $ sData = stream_get_contents ( fopen ( 'php://input' , 'r' ) ) ; $ aData = json_decode ( $ sData , JSON_OBJECT_AS_ARRAY ) ? : [ ] ; $ aData = $ this -> validateUserInput ( $ aData , $ oItem ) ; if ( ! $ this -> oModel -> update ( $ oItem -> id , $ aData ) ) { throw new ApiException ( 'Failed to update resource. ' . $ this -> oModel -> lastError ( ) , $ oHttpCodes :: STATUS_INTERNAL_SERVER_ERROR ) ; } return Factory :: factory ( 'ApiResponse' , 'nails/module-api' ) ; }
Updates an existing resource

@param string $sMethod The method being called

@return array
Updates an existing resource