# |
Apr 20th 2019, 23:05 |
waspinator |
when saving belongs-to-many-associations you can either use an array of properties **OR** a list of _ids, but not both right? `both arrays of properties, as well as a list of ids at the _ids key` https://book.cakephp.org/3.0/en/orm/saving-data.html#saving-belongstomany-associations |
# |
Apr 20th 2019, 14:16 |
waspinator |
perfect, thanks |
# |
Apr 20th 2019, 02:28 |
admad |
Make a table class for it and attached the behaviour. Then specify the class name in belongtomany association using `through` key |
# |
Apr 20th 2019, 01:43 |
waspinator |
is there a way of adding the Timestamp behavior into a join table? |
# |
Apr 19th 2019, 21:09 |
swimboy |
OK, I've reverted the changes I made to the validator code, moved the locale code from the AppController to the bootstrap and now everything is working. Thanks for your help. (I think my original problem was my bootstrap.php file was old and didn't have the I18n block in it like the one you linked to above. I copied that in and referenced the I18n namespaces at the top.) |
# |
Apr 19th 2019, 21:00 |
swimboy |
I was only looking at the validator code to understand what was going on. |
# |
Apr 19th 2019, 20:59 |
swimboy |
I understand that I shouldn't muck around in the validator code, I just wanted to set up the date validator once, instead of each table class file. |
# |
Apr 19th 2019, 20:54 |
admad |
And stop mucking around with the validator code, just specific the format to use when setting up the validator in your table class |
# |
Apr 19th 2019, 20:52 |
admad |
@swimboy you are supposed to enable locale based datetime string parsing here https://github.com/cakephp/app/blob/master/config/bootstrap.php#L181 |
# |
Apr 19th 2019, 20:18 |
swimboy |
If I change the default in ``function dateTime`` and ``function date`` to ``'mdy'`` it works just fine. Obviously, I don't want to do that in a production setting. Is there a way in my own code to override the behavior of the date and dateTime validators in a single location rather than adding it as a separate parameter everywhere I validate a date in a table? |
# |
Apr 19th 2019, 20:12 |
swimboy |
Digging even deeper, I found this line in the Validator.php file: ``` public function dateTime($field, $formats = ['ymd'], $message = null, $when = null)``` which looks to me like the default behavior for date validation is expecting the date in year,month,day order unless another format is specified when the validator is called. It seems to me that this default should pick up the format from setLocaleFormat, should it not? |
# |
Apr 19th 2019, 20:01 |
swimboy |
@ricksaccous I just discovered that the code I had above works, but I had to disable the date validation rule. It would fail if I had a date in any format other than yyyy-MM-dd. Is there somewhere I can tell the validator what format to expect the date to be in (or is there a reason why it would ignore the setLocaleFormat?) |
# |
Apr 19th 2019, 19:05 |
swimboy |
@ricksaccous I'm getting closer, but I'm still missing something. I have this in AppController.php ``` Type::build('datetime')->useLocaleParser()->setLocaleFormat('M/d/yyyy'); Date::setToStringFormat('M/d/yyyy');``` And it displays dates as M/d/yyyy, but it still errors out unless I enter dates as 2019-04-19 |
# |
Apr 19th 2019, 19:00 |
maymeow |
im creating new Note (instead of using it from fixture) on each test because i need to create openssl_signature with logged in user. Its good idea or its better to use fixtures? |
# |
Apr 19th 2019, 18:59 |
maymeow |
Hello Here is my Test for NotesConntroller https://gist.github.com/MayMeow/a60b2847580bdaf9392252264c92ea8b |
# |
Apr 19th 2019, 18:44 |
swimboy |
Yup! I just found that page too. Looking through it now. Seems like it will get me on the right track. Thanks! |
# |
Apr 19th 2019, 18:43 |
ricksaccous |
@swimboy https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data |
# |
Apr 19th 2019, 18:42 |
ricksaccous |
hmmmm |
# |
Apr 19th 2019, 18:42 |
ricksaccous |
so DateTimeType->setLocaleFormat('') and then you can set the format |
# |
Apr 19th 2019, 18:42 |
ricksaccous |
I think in bootstrap or Application.php or something you can setLocaleFormat() |
# |
Apr 19th 2019, 18:41 |
ricksaccous |
if you look at DateTimeType.php |
# |
Apr 19th 2019, 18:41 |
ricksaccous |
i seeeee |
# |
Apr 19th 2019, 18:40 |
swimboy |
Yeah, that gets us right back where we started. The JS is returning it in one format, but CakePHP wants another format. I'm trying to find a way that I can display an input all my dates in m/d/Y format, but have the data saved to the database as Y-m-d. |
# |
Apr 19th 2019, 18:39 |
ricksaccous |
'Y-m-d' |
# |
Apr 19th 2019, 18:38 |
ricksaccous |
i think the format it wants is |
# |
Apr 19th 2019, 18:38 |
ricksaccous |
heheeh |
# |
Apr 19th 2019, 18:38 |
swimboy |
Yeah, that's what it looks like. If I use the standard date picker, it returns an object with year, month, and day values. When I use the JS, it returns the string "4/17/2019". |
# |
Apr 19th 2019, 18:37 |
ricksaccous |
i think cake MIGHT expect a certain format for date in request data to format it into FrozenDate, hmph |
# |
Apr 19th 2019, 18:33 |
swimboy |
Yes, it is. I'm digging into the code, and there's some JS that's generating a pop-up calendar to enter the date. It must be causing a problem with CakePHP being able to parse the input as a date when it's returned. |
# |
Apr 19th 2019, 18:29 |
ricksaccous |
is it a date field in the schema? |
# |
Apr 19th 2019, 18:29 |
ricksaccous |
@swimboy that doesn't sound right at all, it should be just changing it based on it's type |
# |
Apr 19th 2019, 18:13 |
swimboy |
In the request data, it's '4/17/2019' |
# |
Apr 19th 2019, 18:12 |
waspinator |
`$this->request->getQuery('redirect', ['default'])` always returns default |
# |
Apr 19th 2019, 18:12 |
swimboy |
Actually, after patchEntity, the date field is null. |
# |
Apr 19th 2019, 18:08 |
waspinator |
@admad okay, so how would I get the requesting page? I think it used to be in `$this->Auth->redirect()` |
# |
Apr 19th 2019, 18:05 |
swimboy |
frozendate |
# |
Apr 19th 2019, 18:03 |
ricksaccous |
@swimboy after you patchEntity is the date field a frozentime or frozendate object? |
# |
Apr 19th 2019, 18:02 |
swimboy |
@ricksaccous I am calling patchEntity but it was still trying to stuff "4/19/2019" into the date field in my MariaDB table and spitting out SQL errors. |
# |
Apr 19th 2019, 18:01 |
admad |
No it doesn't, home page is just the default value |
# |
Apr 19th 2019, 17:48 |
waspinator |
how would you redirect to the requesting page after logging in using the Authentication plugin? The [example](https://github.com/cakephp/authentication/blob/master/docs/en/migration-from-the-authcomponent.rst#login-action) always redirects to the pages home display |
# |
Apr 19th 2019, 17:47 |
ricksaccous |
as far as displaying dates that's completely up to you to use the Cake Libs available to you |