# |
Jun 14th 2021, 18:56 |
tomrwaller |
Guys - silly question - but what's the difference between customers_ids and customers_.ids? I'm calling a control in a form by control('customers._ids') and that works just fine. However, I'm using beforeMarshal to create some additional entities and I have a query there that looks for $data['customers_ids'). That works if I change the control to control('customers_ids') but it doesn't work if I leave the control as is. |
# |
Jun 14th 2021, 17:37 |
kevin.pfeifer |
have you tried that? https://stackoverflow.com/questions/40609304/cakephp-3-x-optional-language-routing |
# |
Jun 14th 2021, 17:33 |
alamnaryab |
`debug($this->request);` at localhost/project/en |
# |
Jun 14th 2021, 17:32 |
alamnaryab |
I also debugged `$this->request` it is not showing language parameter while I have written code to get language parameter from `request->params` and switch accordingly |
# |
Jun 14th 2021, 17:28 |
alamnaryab |
as now `language` is no more any parameter |
# |
Jun 14th 2021, 17:27 |
alamnaryab |
@admad I added separate route scopes for both languages but before when I was switching language I used below line but now it is not working asdsa |
# |
Jun 14th 2021, 17:03 |
alamnaryab |
better if it can force default language = ar if no lange parameter forun in url |
# |
Jun 14th 2021, 17:02 |
slackebot |
$builder->fallbacks(); }); $routes->prefix('Admin', function (RouteBuilder $routes) { $routes->connect('/', ['controller' => 'Users', 'action' => 'login']); $routes->fallbacks(DashedRoute::class); });``` |
# |
Jun 14th 2021, 17:02 |
alamnaryab |
@admad below is my routes file before Multilanguage, now I have 2 languages , can you plz convert this to for languages (en,ar) ```use Cake\Routing\Route\DashedRoute; use Cake\Routing\RouteBuilder; use Cake\Routing\RouterBuilder; $routes->setRouteClass(DashedRoute::class); $routes->scope('/', function (RouteBuilder $builder) { $builder->connect('/', ['controller' => 'cv', 'action' => 'index']); |
# |
Jun 14th 2021, 16:58 |
alamnaryab |
I am attaching routes output from debugger and also cmd |
# |
Jun 14th 2021, 16:52 |
kevin.pfeifer |
can/should we add a warning to the scope function if such a "placeholder" can be detected? :thinking_face: |
# |
Jun 14th 2021, 16:48 |
admad |
@alamnaryab `scope(':/language')` that's your problem. Scopes can't be place holders/route elements, they need to be static strings. |
# |
Jun 14th 2021, 16:19 |
slackebot |
that Controller/Action/Whatever So it could be that the routes are just being set differently than you expect. Unfortunately I can't tell you how to set your routes so you have a language prefix/scope for your controllers. |
# |
Jun 14th 2021, 16:19 |
kevin.pfeifer |
@alamnaryab I would try to check the "Routes" tab in the DebugKit to see if the routes are actually generated the way you intend them to. Otherwise you could also run `bin/cake routes` in the terminal if you don't have access to the DebugKit to see the same table of active routes. Basically (as far as I know) the route system works like • go through all the available routes • after the first match is present go to |
# |
Jun 14th 2021, 15:25 |
martin |
ok fixed it by setting it to _orginal in entity when I update 1 of the 2 fields :) |
# |
Jun 14th 2021, 15:07 |
martin |
https://github.com/cakephp/cakephp/blob/master/src/Datasource/EntityTrait.php#L304 hmm it just reads out the array from orignal, so does not work with custom made fields :( |
# |
Jun 14th 2021, 15:03 |
martin |
Hmm when you create a virtual field inside a entity. it does not work with getOriginal(‘virtualfieldname’) ? because that already returns the new name (virtuel field just combines 2 fields) |
# |
Jun 14th 2021, 13:55 |
a.vanniel |
I just don't know enough about routing to be able to help you here.. maybe someone else has an idea? |
# |
Jun 14th 2021, 13:55 |
a.vanniel |
is placing the language as the first parameter actually possible with Cake? I am not entirely sure, it does feel like it get's a bit complicated because of this and I am not sure if Cake actually enjoys this way of routing/handling urls... whenever I needed to switch from locale I would add a request variable named lang= of language= but that might not be suitable for you... it might also not be very elegant. |
# |
Jun 14th 2021, 12:12 |
slackebot |
way to debug, currently just hit and try. please help me out in this issue I will also be able to give anydesk access to quickly debug and trace the issue. |
# |
Jun 14th 2021, 12:12 |
slackebot |
$routes ->connect('/', ['controller' => 'Users', 'action' => 'login']) ->setPatterns($patterns); $routes->fallbacks(DashedRoute::class); }); }); $routes->scope('/', function (RouteBuilder $builder) { $builder->connect('/*', ['controller' => 'cv', 'action' => 'index','language'=>'ar'], array('language' => 'en|ar')); $builder->fallbacks(); }); ``` I have no idea what is right |
# |
Jun 14th 2021, 12:12 |
slackebot |
$builder->fallbacks(); }); $routes->scope('/:language', function (RouteBuilder $routes) { $routes->prefix('Admin', function (RouteBuilder $routes) { $patterns = ['language' => 'en|ar']; $routes ->connect('/:controller/:action/*', []) ->setPatterns($patterns); $routes ->connect('/:controller', ['action' => 'index']) ->setPatterns($patterns); |
# |
Jun 14th 2021, 12:12 |
slackebot |
$builder) { $builder->connect('/', ['controller' => 'cv', 'action' => 'index']); $builder->connect('/:language/:controller/:action/*', array(), array('language' => 'en|ar')); $builder->connect('/:language/:controller', array('action' => 'index'), array('language' => 'en|ar')); $builder->connect('/:language', array('controller' => 'cv', 'action' => 'index'), array('language' => 'en|ar')) ; |
# |
Jun 14th 2021, 12:12 |
slackebot |
time getting error saying missing route, while sometime ```Warning (2): preg_match(): Compilation failed: two named subpatterns have the same name (PCRE2_DUPNAMES not set) at offset 42 [CORE\src\Routing\Route\Route.php, line 454]``` my routes are as below ```<?php use Cake\Routing\Route\DashedRoute; use Cake\Routing\RouteBuilder; $routes->setRouteClass(DashedRoute::class); $routes->scope('/:language', function (RouteBuilder |
# |
Jun 14th 2021, 12:12 |
alamnaryab |
I have cakephp4.2 project I have admin prefix I am using Authentication Plugin for admin I also have Localization that is English and Arabic Languages, it worked until the language parameter is saved in session (followed official documentation) but when I needed to show language parameters in URLs and also `$this->Html->link()` automatically add current language parameters to links I tried many things with routing, some |
# |
Jun 14th 2021, 12:02 |
alamnaryab |
ok let me write again with more description |
# |
Jun 14th 2021, 11:56 |
a.vanniel |
I fear that is because it is not clear what your question is... or at least I did not even see anything remotely like a question until i clicked on the reply of your own message. |
# |
Jun 14th 2021, 11:45 |
alamnaryab |
:white_frowning_face: no one is helping me |
# |
Jun 14th 2021, 11:43 |
alamnaryab |
tried many things some time getting missing route some time some other error |
# |
Jun 14th 2021, 11:41 |
dantedantas |
Thanks @kevin.pfeifer. I am new to CakePHP and I didn't have time to improve my knowledge with CakePHP. I will give it a try. If I will have questions, I will come back here to "bother" you. :) Vielen Dank! |
# |
Jun 14th 2021, 11:41 |
slackebot |
$routes ->connect('/:controller/:action/*', []) ->setPatterns($patterns); $routes ->connect('/:controller', ['action' => 'index']) ->setPatterns($patterns); $routes ->connect('/', ['controller' => 'Users', 'action' => 'login']) ->setPatterns($patterns); $routes->fallbacks(DashedRoute::class); }); });``` |
# |
Jun 14th 2021, 11:41 |
slackebot |
$builder->connect('/:language/:controller', array('action' => 'index'), array('language' => 'en|ar')); $builder->connect('/:language', array('controller' => 'cv', 'action' => 'index'), array('language' => 'en|ar')) ; $builder->fallbacks(); }); $routes->scope('/:language', function (RouteBuilder $routes) { $routes->prefix('Admin', function (RouteBuilder $routes) { $patterns = ['language' => 'en|ar']; |
# |
Jun 14th 2021, 11:41 |
alamnaryab |
Cakephp4 Routing with language parameter and admin prefix ```<?php use Cake\Routing\Route\DashedRoute; use Cake\Routing\RouteBuilder; $routes->setRouteClass(DashedRoute::class); $routes->scope('/', function (RouteBuilder $builder) { $builder->connect('/', ['controller' => 'cv', 'action' => 'index']); $builder->connect('/:language/:controller/:action/*', array(), array('language' => 'en|ar')); |
# |
Jun 14th 2021, 11:40 |
alamnaryab |
Cakephp4 Routing with language parameter and admin prefix |
# |
Jun 14th 2021, 11:35 |
kevin.pfeifer |
so if you add a function called `overview` inside any controller you can call that function via `/<controller-name>/overview |
# |
Jun 14th 2021, 11:32 |
kevin.pfeifer |
and the way controllers and its functions are named decides how they can be accessed in the URL see https://book.cakephp.org/4/en/intro/conventions.html |
# |
Jun 14th 2021, 11:32 |
kevin.pfeifer |
thats the public function above in my example |
# |
Jun 14th 2021, 11:31 |
kevin.pfeifer |
well basically a controller action is a function inside a controller :) |
# |
Jun 14th 2021, 11:31 |
dantedantas |
Thank you @kevin.pfeifer. Looks like a great idea. In that case, I only need to create a "controller action"? Maybe do you have a link/website with some kind of explanation on how to do that? Maybe an example? I will start with some tests here. Thank you again. |
# |
Jun 14th 2021, 11:14 |
slackebot |
'data' => $customers->contacts ] ) ); } }``` which you then can call via ```/customers/ajax-get-contacts/<ID>``` |
# |
Jun 14th 2021, 11:14 |
kevin.pfeifer |
e.g. ```// inside the src/Controller/CustomersController.php public function ajaxGetContacts( $id = null ): Response { $request = $this->getRequest(); $response = $this->getResponse(); if( $request->is( 'ajax' ) andand $request->is( 'get' ) ) { $customers = $this->Customers->get($id)->contain(['Contacts']); return $response->withType( 'application/json' ) ->withStringBody( json_encode( [ |