[Flow] RestController - updated Objects are not persisted

Bastian Waidelich bastian at typo3.org
Tue Oct 15 11:26:44 CEST 2013


Robert Berghegger wrote:

Hi Robert & Stephen,

first note that it's *not* true that automatic persistence happens only 
for POST requests! It's only disabled for "safe requests" (usually 
"GET", "HEAD" & "OPTIONS"). See [1]


> If i change my routing from:
>
>    name: 'Single CD URI'
>    uriPattern: 'cd/{cd}'

[...]

>    name: 'Single CD URI'
>    uriPattern: 'cd/{cd.__identity}'

> The Object with updated attributes is passed to the updateAction. I'm
> curious to know why this is happening.

You just hit that "bug": http://forge.typo3.org/issues/45290

Unfortunately this couldn't be solved so that it works completely out of 
the box because it's rather a logical than a technical issue:

The resolved route values are merged with your (body) arguments and

array(
	'cd' => 'b068de1b-e53e-706f-a17e-a7b08176ca92'
)

overrules your

array(
	'cd' => array('title' => 'Eternal Movement', 'artist' => 'Tides from 
nebula')
)

from the request body.

There are two ways to solve this:

1: add the identifier to the body request:

cd[__identity]=b068de1b-e53e-706f-a17e-a7b08176ca92cd&[title]=Eternal 
Movement&cd[artist]=Tides from nebula

..but this is not exactly REST-style

2: Use object routing[1]:

-
   name: 'Single CD URI'
   uriPattern: 'cd/{cd}'
   defaults:
     '@package': 'Berghegger.CD'
     '@controller': 'CD'
   routeParts:
     'cd':
       objectType: 'Berghegger\CD\Domain\Model\CD'

-
   name: 'CD List URI'
   uriPattern: 'cd'
   defaults:
     '@package': 'Berghegger.CD'
     '@controller': 'CD'


NOTE: There currently exists a bug that provokes an exception if you 
don't specify an "uriPattern" for the object-RoutePart. A good chance to 
apply and verify https://review.typo3.org/#/c/24490/ ;)

HTH


[1] 
http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/Routing.html#object-route-parts


-- 
Bastian Waidelich
--
Core Developer Team

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the Flow mailing list