# |
Oct 1st 2016, 16:32 |
ra7bi |
hello |
# |
Oct 1st 2016, 16:17 |
rsadza |
I didn't know about widgets yet, this is great :slightly_smiling_face: |
# |
Oct 1st 2016, 16:16 |
hmic |
additionally, you have a fully working example on it in the core: the datetime datatype and widget |
# |
Oct 1st 2016, 16:15 |
hmic |
it makes it easier to marshall the data and utilizing a widget |
# |
Oct 1st 2016, 16:14 |
hmic |
welcome!# |
# |
Oct 1st 2016, 16:14 |
rsadza |
cool! |
# |
Oct 1st 2016, 16:14 |
rsadza |
Thanks :slightly_smiling_face: I didn't even consider submitting the entire field as an array (I was thinking about having [price] and [price_unit]) |
# |
Oct 1st 2016, 16:13 |
hmic |
if you provide a custom widget, you might get away with that alone, as the formhelper would know the field type (money) and choose a coresponging widget automatically itself! |
# |
Oct 1st 2016, 16:13 |
hmic |
extending the form helper to output a currency field type is a good idea to ease the usage, sure |
# |
Oct 1st 2016, 16:12 |
hmic |
still, you only have one place to deal with that: when marshalling data to the entity. |
# |
Oct 1st 2016, 16:11 |
hmic |
thats it rsadza |
# |
Oct 1st 2016, 16:11 |
hmic |
you would send at least the following data: ['value' => 500, 'currency' => 'EUR', 'unit' => 1 /* 0.01 or 'ct', 'EUR' */] |
# |
Oct 1st 2016, 16:11 |
rsadza |
it currently is, so I am considering adding an input type to the formhelper that adds a hidden field that contains the type (cents / euros) |
# |
Oct 1st 2016, 16:10 |
aro |
anyone seen this? Uncaught Error: Class 'Cake\Error\PHP7ErrorException' not found |
# |
Oct 1st 2016, 16:10 |
hmic |
and your input will not consist of a single field only, will it? |
# |
Oct 1st 2016, 16:09 |
hmic |
you dont change the marshaller |
# |
Oct 1st 2016, 16:09 |
rsadza |
true, the only thing I'm afraid of is that somebody will change an input from cents to euros or vice-versa, and forget to change the marshaller ;) |
# |
Oct 1st 2016, 16:08 |
rsadza |
the Money class keeps the information (Money::EUR(500) = 5.00 euro), but you still need to know if you should multiply by 100 |
# |
Oct 1st 2016, 16:07 |
hmic |
if it's not. you know when to apply it: when marshalling data to the entity. you have a marshaller for the money class anyways, put the code there so it's all in one place and not duplicated whatsoever |
# |
Oct 1st 2016, 16:06 |
hmic |
rsadza: isn't it the money class to take care of all of that details? |
# |
Oct 1st 2016, 15:59 |
rsadza |
Is there some way to do this in a nice way? I think that the best place to define if the value will need to be converted is in the Form helper, so that if we switch the input from euros to eurocents, we don't need to change code elsewhere. |
# |
Oct 1st 2016, 15:57 |
slackebot |
convert it to Money(), we need to parse the input data (e.g. replace comma by dot) and multiply by 100 if its not in cents. If we would do this in the Entity, the Entity would have knowledge of the input type, but we also don' t want to clutter our controller. |
# |
Oct 1st 2016, 15:57 |
rsadza |
I have a question regarding converting request data to an Entity. In our application we are using the moneyphp/money object to represent currencies, to prevent bugs due to multicurrency (e.g. accidentally adding euros to dollars). We are unsure where we should convert the request data to the money object. It would make sense to use the beforeMarshall / setter methods. However: in some cases users can enter money in cents, in some cases in euro |
# |
Oct 1st 2016, 15:51 |
rsadza |
Hi guys! |
# |
Oct 1st 2016, 14:44 |
ndm |
Most probably the better choice in that case. |
# |
Oct 1st 2016, 14:41 |
thinkingmedia |
``` $routes->connect('/follow',[ 'prefix'=>'Api/Boards', 'controller'=>'Follow', 'action'=>'edit', '_method'=>'PUT' ]); ``` |
# |
Oct 1st 2016, 14:41 |
thinkingmedia |
I ended up doing my own connect. I think later it's easier to read and see what I was intending. |
# |
Oct 1st 2016, 14:40 |
ndm |
@thinkingmedia Have to correct myself, while the default path value is `:id` in the default resource map configuration, when overwriting/creating a resource action, the default path value is the name of the resource, ie `update` and `delete` in this case. Anyhow, passing an empty path is what does the trick. |
# |
Oct 1st 2016, 14:24 |
thinkingmedia |
ah for sure, I get it. thanks :slightly_smiling_face: |
# |
Oct 1st 2016, 14:04 |
ndm |
The path is being appended to the `$url` argument when connecting the route |
# |
Oct 1st 2016, 14:04 |
ndm |
Because that's what does the trick, the default path is `:id` |
# |
Oct 1st 2016, 14:03 |
thinkingmedia |
@ndm thanks! Why did you set path to an empty string? |
# |
Oct 1st 2016, 14:02 |
ndm |
@thinkingmedia By creating the routes completely on your own, or by modifying the default resource map for `RouteBuilder::resources()` so that the path doesn't contain any ID route elements, like https://gist.github.com/ndm2/30c59b00326c4d5fd71a5237b9d73527 |
# |
Oct 1st 2016, 13:48 |
sandeep_ |
Hi |
# |
Oct 1st 2016, 13:29 |
thinkingmedia |
How can I create a REST resource that can `update` and `delete` without an `ID`? |
# |
Oct 1st 2016, 13:12 |
prophet |
'foreignKey' => 'user_id' that is wrong. It has to be 'association_id'. That fixed it. Thanks hmic. |
# |
Oct 1st 2016, 13:11 |
prophet |
Oh wait. |
# |
Oct 1st 2016, 13:10 |
prophet |
yes, that is what I did |
# |
Oct 1st 2016, 13:08 |
hmic |
in the belongstomany one |
# |
Oct 1st 2016, 13:08 |
prophet |
You mean: 'foreignKey' => 'user_id' ? Nothing changed |
# |
Oct 1st 2016, 13:06 |
hmic |
so you need to add the corect association keys |