Log message #4265922

# At Username Text
# Jun 21st 2021, 11:47 slackebot1 or /pages/display/home to be returned. Is this as all possible?
# Jun 21st 2021, 11:47 a.vanniel Does anybody know if there is a way to filter a user supplied url? Basically what I would like to do is populate a query variable and I want to sanitize this variable so it does not contain an external url... I thought passing something to Router::url() would solve my problems but when I pass somethign like https://www.google.com to Router::url() I am just getting the same url back, instead I would have liked something like /
# Jun 21st 2021, 10:19 kevin.pfeifer @alamnaryab what are you trying to accomplish with that logic? As far as I know the `$connection->rollback();` only works for manually executed queries like ```$connection->execute('UPDATE articles SET published = ? WHERE id = ?', [true, 2]);``` If you go through the ORM with `$connection->Tags->save($tag)` you can’t rollback from that. But again, what are you trying to accomplish?
# Jun 21st 2021, 09:16 kupe3b thansk @erwane
# Jun 21st 2021, 07:59 erwane https://book.cakephp.org/4/en/views/helpers/form.html#creating-select-pickers
# Jun 21st 2021, 07:59 erwane so `<?= $this->Form->control('fieldname', ['multiple' => 'checkbox', 'options' => $selectOptions]) ?>`
# Jun 21st 2021, 07:58 erwane ```Attributes for Select Pickers 'multiple' - If set to true allows multiple selections in the select picker. If set to 'checkbox', multiple checkboxes will be created instead. Defaults to null.```
# Jun 21st 2021, 07:38 kupe3b hello, when baking views, in many-to-many relations a <select> tag is generated with multi-selection enabled. Is there an easy way to make it generate list of checkboxes instead?
# Jun 21st 2021, 06:43 erwane `displayField` ?
# Jun 21st 2021, 06:40 paolo.bragagni hi I'm trying to get in form.twig the name of the 'title' in associated table. I mean the name of the default field used for 'title'.
# Jun 21st 2021, 06:01 slackebot1 $connection->rollback();//*********** this rollback is not working record is saved in DB $this->Flash->success(__('The tag has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('The tag could not be saved. Please, try again.')); }```
# Jun 21st 2021, 06:01 alamnaryab Good morning having issue with transactions https://book.cakephp.org/4/en/orm/database-basics.html#using-transactions ``` if ($this->request->is('post')) { $connection = ConnectionManager::get('default'); $connection->begin(); $tag = $connection->Tags->patchEntity($tag, $this->request->getData()); if ($connection->Tags->save($tag)) {
# Jun 20th 2021, 17:13 ndm you're welcome
# Jun 20th 2021, 17:13 amayer Thanks for pointing me down the right path @ndm!
# Jun 20th 2021, 17:12 amayer Looks like `$config = ConnectionManager::getConfig('default'));` is what I was looking for!
# Jun 20th 2021, 17:00 amayer I'll give the ConnectionManager thing a try.
# Jun 20th 2021, 16:59 ndm well there you go :)
# Jun 20th 2021, 16:59 ndm Some configuration is "consumed", meaning it is being removed from the config after reading, and then it's only available via the consumers, in your case the connections. Try `\Cake\DataSource\ConnectionManager::get('default')->getConfig()`
# Jun 20th 2021, 16:59 amayer I may have found the issue... Looks like `Datasources` is being consumed in config/bootstrap.php
# Jun 20th 2021, 16:50 amayer Hello, I am writing a plugin (composer package) and would like to retrieve the `Datasources.default` settings using `\Cake\Core\Configure::read()`, but it doesn't seem to have a value. All other settings in my config/app_local.php (main application, cakephp 4.2.7) seem to be there. Is there a reason I can't access `Datasources.default` from a plugin?
# Jun 20th 2021, 13:14 ndm As you've done it in your snippet would be one way, it should work fine for date/time objects that are being casted to string. But as mentioned, your output looks like the default JSON encode format, the default to string format is i18n aware, and will never give you the format that's shown in your output.
# Jun 20th 2021, 13:12 alamnaryab I need one format that is `yyyy-MM-dd HH:mm:ss` for any Language/Locale all the users are in same timezone, where and how can I set?
# Jun 20th 2021, 13:10 ndm Indeed, it depends. If he'd need all output in the same format, then setting a default to string format could work just fine. But that's different from timezone conversions, the to string logic isn't aware of timezones, only of formats. All that being said, his snippet should have worked fine, so there must be something else to it. That example output looks like the default JSON encode format.
# Jun 20th 2021, 13:02 kevin.pfeifer I was just thinking in the example of @alamnaryab where he just wants to show a different datetime format for a different language prefix. Instead of having to adjust all outputted datetime fields in the template there should be somse sort of global default which can be overwritten by e.g. a language prefix. sure it is all very customizable but as you said it all depends on the usecase ^^
# Jun 20th 2021, 12:56 ndm If you'd have dates with different timezones, you'd have to store that timezone in the DB alongside, and you'd have to come up with something on your own, a custom helper would be easy enough.
# Jun 20th 2021, 12:55 ndm Yeah, it's called `outputTimezone`
# Jun 20th 2021, 12:55 ndm Unfortunately proper documentation for this is lacking... it's a somewhat complicated topic, so that's not too surprising. It really depends on the requirements of your application, if for example all dates should be converted to the same timezone, the time helper has a config option for that IIRC.
# Jun 20th 2021, 12:51 kevin.pfeifer so datetime fields for e.g. created and modified should be saved in UTC (therefore looking into the database via sql cli or phpmyadmin should show UTC values). But where in cakephp (in a multilingual setup) do I have to add the logic to show different formats and/or timezones? Is there a guide somewhere?
# Jun 20th 2021, 12:46 slackebot1 required, even if it's more work. I never not ran into a hot steaming pile of trouble when doing timezone conversions for saving/reading.
# Jun 20th 2021, 12:46 slackebot1 imagine that this can make things extra annoying :) `TIMESTAMP` is converted from server/connection timezone to UTC on save, and from UTC to server/connection timezone on read (this is what the datasource config timezone would be used for). As always when this topic comes up, I'd like to mention that from my personal experience, I can only suggest to go UTC all the way, and convert to specific timezones on PHP/frontend level when
# Jun 20th 2021, 12:46 ndm @kevin.pfeifer `DATETIME` columns can hold a timezone offset (not a timezone name) as of MySQL 8. CakePHP accepts such formats even for the default `DateTimeType` class, but it won't save it like that, only the `DateTimeTimezoneType` does, which however isn't automatically mapped. Also MySQL will not return the offset when doing a select, instead it will return the date with the offset subtracted. I haven't tried it yet, but I could
# Jun 20th 2021, 10:36 kevin.pfeifer i guess i am mixing up the `datetime` mysql field with the `timestamp` field timestamp is always utc, datetime can "save" timezones
# Jun 20th 2021, 10:31 kevin.pfeifer As far as I know there are • the timezone the data is saved in the database (in a datetime column, or is this always UTC?) • the timezone setting present in the datasource config (which should be the same as the data saved in the database as far as I know) • the `setToStringFormat` from above • and there are view helpers as well to change the format for php datetime objects
# Jun 20th 2021, 10:20 dereuromark localized output vs default (code/iso) output
# Jun 20th 2021, 10:20 kevin.pfeifer Guess I have to go a bit deeper here to fully understand where date formats (and maybe timezones as well( are present and can/should be changed
# Jun 20th 2021, 10:18 kevin.pfeifer I am sorry but what do you mean by "both" here?
# Jun 20th 2021, 10:14 dereuromark at least when local date format != code one
# Jun 20th 2021, 10:13 dereuromark because you are using it for both (which works, but is maybe not the best idea)
# Jun 20th 2021, 10:10 kevin.pfeifer but then why does the `setToStringFormat` work for me without that helper?
# Jun 20th 2021, 09:43 dereuromark most bake templates have that properly built in, though, https://github.com/dereuromark/cakephp-setup/blob/master/templates/bake/Template/view.twig#L95 etc
# Jun 20th 2021, 09:42 dereuromark the string casting default format is mainly for code output (e.g. in json formatting)