# |
Jun 22nd 2021, 18:07 |
madjid.gacem |
```$this->customerTable = TableRegistry::getTableLocator()->get('Customers', [ 'className' => CustomerTable::class, ]);``` |
# |
Jun 22nd 2021, 18:07 |
madjid.gacem |
@kevin.pfeifer thank u for the link, technically i'm working on a separate boundedContext the tables are located inside the infrastructure folder, i managed to make it working by using this approach |
# |
Jun 22nd 2021, 18:05 |
kevin.pfeifer |
@madjid.gacem according to https://stackoverflow.com/questions/47717720/organize-models-in-subdirectories-cakephp-3 you would have to create your own TableLocator which contains that Subfolder. Instead I would highly recommend to split your code into a plugin instead of using subfolders |
# |
Jun 22nd 2021, 17:57 |
madjid.gacem |
Hi there, guys i've a CustomerTable into a separate folder with its own namespace, how can i get an instance of it using ```TableRegistry::getTableLocator()->get('Customers')``` ? |
# |
Jun 22nd 2021, 17:30 |
kevin.pfeifer |
I would create a custom finder method in the other model, call that in the controller where I need it and set the result as a separate array in the view. If they don’t actually have any connection at all, why should the data be accessed via an entity field? |
# |
Jun 22nd 2021, 17:20 |
kevin.pfeifer |
or use a svg :P |
# |
Jun 22nd 2021, 17:19 |
dereuromark |
time upgrade :P |
# |
Jun 22nd 2021, 17:18 |
kevin.pfeifer |
uh, fontaweomse 4.6.3 doesn’t have a discord icon… |
# |
Jun 22nd 2021, 17:05 |
kevin.pfeifer |
didn't know the cakephp.org page itself is a accessable repository as well :) I will make a PR which adds the discord link in the same area where the slack link is present |
# |
Jun 22nd 2021, 16:46 |
kevin.pfeifer |
what SQL would you like to represent in such an association? |
# |
Jun 22nd 2021, 16:45 |
ndm |
What would you want that association to use for establishing relations instead? Baked potatoes? |
# |
Jun 22nd 2021, 16:26 |
kevin.pfeifer |
is it possible to add that discord link to https://cakephp.org/get-involved |
# |
Jun 22nd 2021, 16:24 |
kevin.pfeifer |
well hello there |
# |
Jun 22nd 2021, 16:22 |
kevin.pfeifer |
well then you got things to learn :) |
# |
Jun 22nd 2021, 16:21 |
NMND |
I don't even know what slack is. :D |
# |
Jun 22nd 2021, 16:21 |
NMND |
Well I removed all your answer by hitting ctrl which deleted it but as I got most of it, it works now. Many Thanks! :) |
# |
Jun 22nd 2021, 16:21 |
kevin.pfeifer |
and btw: there is a slack channel ;) https://cakesf.herokuapp.com/ |
# |
Jun 22nd 2021, 16:13 |
kevin.pfeifer |
and then just check if that object is empty or not via `if( !empty( $identity ) ):` |
# |
Jun 22nd 2021, 16:13 |
kevin.pfeifer |
basically you can get the $identity object via `$identity = $this->getRequest()->getAttribute( 'identity' );` |
# |
Jun 22nd 2021, 16:12 |
NMND |
That message got ripped apart by no markup within the IRC client. (srsly, why is there no discord? :/ ) but I'll try to sort it and figure it out, thanks! :) |
# |
Jun 22nd 2021, 16:08 |
kevin.pfeifer |
```/** @var Authorization\Identity $identity */ $identity = $this->getRequest() ->getAttribute( 'identity' ); <?php if( !empty( $identity ) ): ?> <?= $this->Html->link( sprintf('Logout (%s)', $identity->getOriginalData()->username), [ 'controller' => 'Users', 'action' => 'logout', 'plugin' => 'CakeDC/Users' ] ) ?> <?php else: ?> <?= $this->Html->link( 'Login', [ |
# |
Jun 22nd 2021, 16:08 |
slackebot1 |
'controller' => 'Users', 'action' => 'login', 'plugin' => 'CakeDC/Users' ] ) ?> <?php endif; ?>``` |
# |
Jun 22nd 2021, 15:52 |
NMND |
Sers. Total Newb using v4.x here. Got through the tutorial. I will need some tutoring until I understand how this works. I HTMLd myself a few buttons into default.php. Now I'd like to replace the login button with a logout button when the user is logged in. Anyone able to spoonfeed or post a up2date tutorial? |
# |
Jun 22nd 2021, 13:00 |
erwane |
it's pretty cool to have localized URL's but .... not really usefull and SEO is not only based on that. |
# |
Jun 22nd 2021, 12:57 |
david |
Thank you guys... I think I will desist in this |
# |
Jun 22nd 2021, 12:56 |
erwane |
Now i'mu using the AdMad i18n plugin and don't translate routes. |
# |
Jun 22nd 2021, 12:56 |
erwane |
Package : <https://packagist.org/packages/erwane/cakephp-i18n-url> Source : <https://github.com/Erwane/cakephp-i18nUrl/tree/4.x> I abandonned the idea. Very complex to maintain. But it work like that : https://pastebin.com/jzXgWJrN |
# |
Jun 22nd 2021, 12:48 |
erwane |
I've done something like that earlier. I'll check if code is public |
# |
Jun 22nd 2021, 12:36 |
kevin.pfeifer |
puh, I haven't dealt with these "translation depths" so sorry, I can't help you any more ,:) |
# |
Jun 22nd 2021, 12:35 |
david |
and I dont't want to du'plicate each url in router.php |
# |
Jun 22nd 2021, 12:34 |
david |
because I can't translate strings in router.php |
# |
Jun 22nd 2021, 12:34 |
david |
No, I have a function "actionDispatcher" |
# |
Jun 22nd 2021, 12:33 |
kevin.pfeifer |
and are you translating urls via `__d('urls', '/english-slug');` ? So do you manually set new routes in your config/router.php if you change some slugs? |
# |
Jun 22nd 2021, 12:32 |
kevin.pfeifer |
the whole translation system relies on the fact, that you stick with one language in your source code and that base language is being translated to whatever is currently active. Therefore your desired functionality can't work. |
# |
Jun 22nd 2021, 12:27 |
david |
I18n::setLocale('es_ES'); echo __('hola'); // prints "hola" I18n::setLocale('en_GB'); echo __('hola'); // prints "hello" The problem, because I am trying to translate a translation: I18n::setLocale('es_ES'); echo __('hello'); // prints "hello" |
# |
Jun 22nd 2021, 12:24 |
dereuromark |
you could switch the translation language at runtime for each, and then reset. but it might be easier to just hardcode this one then. |
# |
Jun 22nd 2021, 12:23 |
david |
when I "paint" the link to change to spanish version, I can't obtain the spanish string because I am trying to translate __d('urls', '/english-slug'); |
# |
Jun 22nd 2021, 12:22 |
david |
the problem is when I am in english (mydomain.com/en) |
# |
Jun 22nd 2021, 12:22 |
david |
no, that works fine |
# |
Jun 22nd 2021, 12:21 |
kevin.pfeifer |
but when changing to english, you want to load the text from the `en/default.po` and it doesn't` |
# |
Jun 22nd 2021, 12:21 |
david |
in spanish there is no problem |
# |
Jun 22nd 2021, 12:21 |
david |
yes, that is |
# |
Jun 22nd 2021, 12:20 |
kevin.pfeifer |
so your spanish text is all good and if your current active language is spanish then everything is fine, right? |
# |
Jun 22nd 2021, 12:18 |
david |
so, if translation doesn't exists, I get the spanish string |
# |
Jun 22nd 2021, 12:18 |
david |
I only have "/en" translations |
# |
Jun 22nd 2021, 12:17 |
david |
my default lang is "es", so "/es" doesn't exists |
# |
Jun 22nd 2021, 12:17 |
kevin.pfeifer |
so do you have ```/src /Locale /en default.po /es default.po``` |
# |
Jun 22nd 2021, 12:14 |
david |
3 |
# |
Jun 22nd 2021, 12:14 |
kevin.pfeifer |
first of all, are you on cakephp 4 or 3? |
# |
Jun 22nd 2021, 12:14 |
david |
it is correct |
# |
Jun 22nd 2021, 12:13 |
kevin.pfeifer |
so you are outputting your text via `__('English')` but it is being translated because your current language not englisch |
# |
Jun 22nd 2021, 12:12 |
kevin.pfeifer |
i guess i know what the problem is |
# |
Jun 22nd 2021, 12:12 |
david |
Iterating the translations is not a problem, but when I am in a translation, I can't figure how to get the default language string |
# |
Jun 22nd 2021, 12:11 |
david |
yes, it should be different |
# |
Jun 22nd 2021, 12:10 |
kevin.pfeifer |
by "each language" i mean each "currently active language" |
# |
Jun 22nd 2021, 12:07 |
kevin.pfeifer |
and the text shown in your language dropdown should be different for each language, right? |
# |
Jun 22nd 2021, 12:05 |
david |
my current url es mydomain.com/en/categories and I want to change to to mydomain.com/es/categorias |
# |
Jun 22nd 2021, 12:04 |
david |
for example |
# |
Jun 22nd 2021, 12:03 |
kevin.pfeifer |
what do you mean by the current section? |
# |
Jun 22nd 2021, 12:00 |
david |
I want to change the language, but keep in the current section. So I need to know the url segment of the current url |
# |
Jun 22nd 2021, 11:58 |
david |
I am trying to do a dropdown menu for changing the language of the current url |
# |
Jun 22nd 2021, 11:56 |
kevin.pfeifer |
besides the fact, that multiple translation "keys" can have the same translation, so you could run into the problem, that your given "translated text" appears multiple times in your .po file |
# |
Jun 22nd 2021, 11:54 |
kevin.pfeifer |
maybe you try to fix a problem which can be done easier otherwise |
# |
Jun 22nd 2021, 11:53 |
kevin.pfeifer |
but what are you trying to accomplish with that? |
# |
Jun 22nd 2021, 11:52 |
kevin.pfeifer |
and search through that manually if you really really want to |
# |
Jun 22nd 2021, 11:52 |
kevin.pfeifer |
you can ge tthe whole translation package via ``` $translator = I18n::getTranslator(); $package = $translator->getPackage();``` |
# |
Jun 22nd 2021, 11:52 |
erwane |
the `__` function call ` ```I18n::getTranslator()->translate($singular, $args);``` You can set you own translator, who search in ALL pot files for string and return original. |
# |
Jun 22nd 2021, 11:50 |
erwane |
but it's very weird request ;) |
# |
Jun 22nd 2021, 11:50 |
erwane |
Maybe you can write you own translator |
# |
Jun 22nd 2021, 11:44 |
david |
If I set a locale in runtime via I18n::setLocale(), I can get the translation of a string. Is there any way to do in the inverse way? Given a translation, get the original string. |
# |
Jun 22nd 2021, 11:42 |
david |
morning :) |
# |
Jun 22nd 2021, 11:39 |
kevin.pfeifer |
But I guess all these structures have their meaning and reason, even if we sometimes don't get it instantly :) |
# |
Jun 22nd 2021, 11:39 |
kevin.pfeifer |
to be honest i too had to fiddle with these things quite some time till i got it working :) |
# |
Jun 22nd 2021, 11:38 |
neon1024 |
Success! Thanks again for the tips @kevin.pfeifer appreciate the help |
# |
Jun 22nd 2021, 11:35 |
neon1024 |
The fact that CookieCollection is immutable caught me out |
# |
Jun 22nd 2021, 11:21 |
neon1024 |
Might be time for a coffee break ,:) |
# |
Jun 22nd 2021, 11:19 |
neon1024 |
Oh, good spot |
# |
Jun 22nd 2021, 11:19 |
kevin.pfeifer |
you need to set the CookieColleciton on the response, not the request |
# |
Jun 22nd 2021, 11:19 |
kevin.pfeifer |
you mixed request and repsonse there FYI |
# |
Jun 22nd 2021, 11:18 |
kevin.pfeifer |
would be something like ```$cookie_collection = $this->getRequest()->getCookieCollection()->add($cookie); $new_response = $this->getResponse()->withCookieCollection($cookie_collection) $this->setResponse($new_response);``` |
# |
Jun 22nd 2021, 11:17 |
neon1024 |
Thanks @kevin.pfeifer I’ll give this approach a try :bow: |
# |
Jun 22nd 2021, 11:17 |
kevin.pfeifer |
can ge quite lengthy :) |
# |
Jun 22nd 2021, 11:17 |
kevin.pfeifer |
and if you want to stick to the getter/setter methods sure |
# |
Jun 22nd 2021, 11:16 |
kevin.pfeifer |
thats why I always like to make a copy of the request with `$request = $this->getRequest()` and work with that variable unless i need to set it back |
# |
Jun 22nd 2021, 11:16 |
neon1024 |
imeanimsureitcouldbelongerifwejustaddedsomemorenestedmethodsintotherebutyoucantbetoocarefullthesedaysyouknow |
# |
Jun 22nd 2021, 11:16 |
kevin.pfeifer |
,:) |
# |
Jun 22nd 2021, 11:16 |
neon1024 |
`$this->setRequest($this->getRequest()->withCookieCollection($this->getRequest()->getCookieCollection()->add($cookie)));` oof |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
``` // Only save cookie if user selected it if(!empty($data['remember_my_data'])){ $cookie = Cookie::create( 'remember_my_data', $data ); $this->response = $this->response->withCookie( $cookie ); } else { $this->response = $this->response->withExpiredCookie(new Cookie('remember_my_data')); } return $this->redirect( [ 'controller' => |
# |
Jun 22nd 2021, 11:15 |
slackebot1 |
'pages', 'action' => 'display', 'success' ] );``` |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
I don’t return the response instance, i just do a redirect |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
or whatever |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
before redirecting |
# |
Jun 22nd 2021, 11:15 |
kevin.pfeifer |
could be that you need to adjust the returned cookie collection as well |
# |
Jun 22nd 2021, 11:14 |
neon1024 |
…and return that response instance I suppose? |
# |
Jun 22nd 2021, 11:14 |
kevin.pfeifer |
but you need to set it back into the response as well |
# |
Jun 22nd 2021, 11:14 |
kevin.pfeifer |
well your code above returns the new cookie collection |
# |
Jun 22nd 2021, 11:13 |
neon1024 |
Not an intuitive api for sure imho |
# |
Jun 22nd 2021, 11:12 |
neon1024 |
I wonder what all this CookieCollection business is about then :thinking_face: |
# |
Jun 22nd 2021, 11:12 |
neon1024 |
I guess it just dies when the request instance does |
# |
Jun 22nd 2021, 11:12 |
kevin.pfeifer |
i did it like that |