# |
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: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 |
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: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 |
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( [ |
# |
Jun 14th 2021, 11:14 |
slackebot |
'data' => $customers->contacts ] ) ); } }``` which you then can call via ```/customers/ajax-get-contacts/<ID>``` |
# |
Jun 14th 2021, 11:10 |
kevin.pfeifer |
@dantedantas instead of trying to re-invent the wheel by ourself and handle your AJAX request by ourself inside the webroot folder why not create a controller action which you call via AJAX? Then you are “in the environment” of CakePHP and don’t need to do the whole bootstrapping by ourself |
# |
Jun 14th 2021, 11:08 |
admad |
Bringing any over a decade old app upto would be a rewrite, unless maybe it's WP since it never progressed. |
# |
Jun 14th 2021, 11:05 |
admad |
Rewrite |
# |
Jun 14th 2021, 10:56 |
arthurb |
Morning gents, I have a new client thats running a CakePHP v1.3.21 application and his asking us to quote on upgrading it to v4. In your experience what will be the easiest, upgrade to V2 to V3 to V4 or rewrite from scratch? thanks :) |
# |
Jun 14th 2021, 10:56 |
dantedantas |
Dear All, please, could someone explain to me how could I from the folder webroot connect to the DB? I have tried without success: Or maybe I have another choice? So, what I am doing and why: I have a VIEW that is very slow because loads a lot of data. What I did is: I created a horizontal menu and when you click on the button I use AJAX to load the needed info. The files used with AJAX are located in webroot’s folder. |
# |
Jun 14th 2021, 10:56 |
slackebot |
*image* *1209×424 25 KB* Thank you for your attention and help. Link: https://discourse.cakephp.org/t/how-to-connect-db-from-webroots-folder/9436 |
# |
Jun 14th 2021, 10:54 |
dantedantas |
Servus! :) |
# |
Jun 14th 2021, 10:54 |
kevin.pfeifer |
servus :) |
# |
Jun 14th 2021, 10:53 |
dantedantas |
Hello from Wien. :) |
# |
Jun 14th 2021, 10:50 |
slackebot |
<kevin.pfeifer> |
# |
Jun 14th 2021, 10:49 |
kevin.pfeifer |
a .pot is just a template file from which you generate your .po files for your languages. If you want to have the same string in the msgid and the msgstr use the Software PoEdit, select all strings and go to Edit => “Copy from Source Text” |
# |
Jun 14th 2021, 10:46 |
Lac |
I actually do need it ^^ |
# |
Jun 14th 2021, 10:38 |
dereuromark |
so no need to do such a thing |
# |
Jun 14th 2021, 10:38 |
dereuromark |
exactly :) my point is that it is as expected once you actually use it |
# |
Jun 14th 2021, 10:31 |
Lac |
my msgstr is always empty |
# |
Jun 14th 2021, 10:30 |
dereuromark |
why is that needed? it is by default this when it is empty |
# |
Jun 14th 2021, 10:29 |
Lac |
Hey guys, does anyone know if there's are way to set the msgstr the same as the msgid when generating a pot file through the i18n extract ? Thanks ! |
# |
Jun 14th 2021, 10:10 |
y.teruyacookie |
Thank you for your reply. I’m sorry, I confirm that results of debug($reserves) and debug($cancels) are different. |
# |
Jun 14th 2021, 08:15 |
val |
What would be the correct way to destroy an instance of MyTable class in 3.x so that it would be removed from all places where it is referenced or cached? |
# |
Jun 14th 2021, 08:05 |
alamnaryab |
? |
# |
Jun 14th 2021, 07:13 |
alamnaryab |
would you be able to get my anydesk or teamviewer and debug if I am making any mistake? |
# |
Jun 14th 2021, 07:12 |
alamnaryab |
thank you for your time |
# |
Jun 14th 2021, 07:09 |
conehead |
Really cannot imagine that |
# |
Jun 14th 2021, 07:08 |
conehead |
So if you remove the lines from the scope again it is working without any admin prefix? |
# |
Jun 14th 2021, 07:08 |
conehead |
There must be something other different. |
# |
Jun 14th 2021, 07:06 |
alamnaryab |
if link is there then how it was wroking for non-admin before adding admin scope instead of prefix as you suggested |
# |
Jun 14th 2021, 07:04 |
conehead |
Probably because you are trying to add a link to it? |
# |
Jun 14th 2021, 07:03 |
alamnaryab |
I am on domain/en it is showing error: A route matching "array ( 'prefix' => 'Admin', 'controller' => 'Users', 'action' => 'login', 'plugin' => NULL, '_ext' => NULL, )" could not be found. |
# |
Jun 14th 2021, 07:02 |
alamnaryab |
Missing Route |
# |
Jun 14th 2021, 07:02 |
alamnaryab |
now even non admin also showing error |
# |
Jun 14th 2021, 06:59 |
conehead |
I mean you are not following standards. You expect a prefix not to be on the first position...which is pretty much the definition of a prefix |
# |
Jun 14th 2021, 06:57 |
conehead |
couldnt you just move the routes from the admin prefix to the scope '/' and manually add the admin prefix there? |
# |
Jun 14th 2021, 06:42 |
alamnaryab |
then url becomes as domain/admin/en/controller/action while I need language first then admin |
# |
Jun 14th 2021, 06:41 |
filipecamargo10 |
```$builder->connect('/:language/:controller/:action/*', array(), array('language' => 'en|ar'));``` You have to do the same thing in admin routes |
# |
Jun 14th 2021, 06:41 |
alamnaryab |
admin inside language |
# |
Jun 14th 2021, 06:40 |
alamnaryab |
I tried many things, with that version problem is with admin |
# |
Jun 14th 2021, 06:40 |
filipecamargo10 |
the problem is on admin routes |
# |
Jun 14th 2021, 06:38 |
alamnaryab |
waiting since last week |
# |
Jun 14th 2021, 06:37 |
alamnaryab |
https://discourse.cakephp.org/t/cakephp-4-admin-prefix-routing-with-i18n-language-parameter/9431 |
# |
Jun 14th 2021, 06:37 |
filipecamargo10 |
right |
# |
Jun 14th 2021, 06:37 |
alamnaryab |
https://stackoverflow.com/questions/67888105/cakephp-4-admin-prefix-routing-with-i18n-language-parameter |
# |
Jun 14th 2021, 06:37 |
alamnaryab |
localization and admin prefix routing |
# |
Jun 14th 2021, 06:37 |
filipecamargo10 |
what u need ? |
# |
Jun 14th 2021, 06:36 |
alamnaryab |
I am having issue with cakephp4 routing, can I get help here? |
# |
Jun 14th 2021, 06:36 |
conehead |
hello |
# |
Jun 14th 2021, 06:36 |
alamnaryab |
hello all |
# |
Jun 14th 2021, 06:35 |
johncakeboss |
irc is so nostalgic |
# |
Jun 14th 2021, 06:27 |
conehead |
@y.teruyacookie as you are using two custom finder methods that we do not know, this is very much possible that this is true. The name of the finder is not part of the object, so if the content of the finders is the same, but the name differs, it still can be true. did you try debug($cancels) and debug($reserves) and compare them by hand? Do they differ? debug($query->find() === $query->find('list')) is false for me |
# |
Jun 14th 2021, 06:11 |
other |
hi |
# |
Jun 14th 2021, 05:43 |
alamnaryab |
https://stackoverflow.com/questions/67888105/cakephp-4-admin-prefix-routing-with-i18n-language-parameter |
# |
Jun 14th 2021, 05:43 |
alamnaryab |
I am facing problem with cakephp4 i18n and admin routing since last week, hopefully here someone will help me. |
# |
Jun 14th 2021, 05:40 |
alamnaryab |
Good morning |
# |
Jun 14th 2021, 05:40 |
alamnaryab |
hi |
# |
Jun 14th 2021, 01:03 |
y.teruyacookie |
When I run the following DEBUG, it returns true, but I wonder why. ```$reserves = $query->find('Reserve', $options); $cancels = $query->find('Cancel', $options); debug($cancels === $reserves); // true is returned``` |
# |
Jun 13th 2021, 15:18 |
kiril.zvezdakoski |
just joined. regards to everyone here :) |
# |
Jun 13th 2021, 13:23 |
admad |
@angelxmoreno Crud plugin doesn't have much to do with routes. It comes into picture after the URL has already parsed into controller - action based on routes you set. |
# |
Jun 13th 2021, 13:20 |
admad |
@dereuromark yes, but that's for people to figure out for themselves :P |
# |
Jun 13th 2021, 12:49 |
dereuromark |
@admad Isnt there a long answer, like you could configure an additional lookup path and so on .. :) ? |
# |
Jun 13th 2021, 12:13 |
angelxmoreno |
greetings bakers! does the Crud Plugin support routes like `/rooms/123/members` using CakePHP 3.x and CrudPlugin 5.x ? |
# |
Jun 13th 2021, 11:51 |
kevin.pfeifer |
blobo, I would guess there is either • a notice or warning being outputted before the pdf is rendered (check your log directory) or • you unintentionally echo some string before the pdf is being rendered |
# |
Jun 13th 2021, 11:49 |
admad |
No. |
# |
Jun 13th 2021, 11:14 |
david |
is it possible to load an element out of the default "Element" location? |
# |
Jun 13th 2021, 11:13 |
david |
morning |
# |
Jun 13th 2021, 08:45 |
blobo |
help would be much appreciated |
# |
Jun 13th 2021, 08:45 |
blobo |
hello, help needed. I generate pdf with errors: <b>Warning</b> (2)</a> |
# |
Jun 13th 2021, 08:45 |
blobo |
: Cannot modify header information - headers already sent |
# |
Jun 13th 2021, 07:37 |
kevin.pfeifer |
ah, good to know thx :) |
# |
Jun 13th 2021, 07:36 |
admad |
@kevin.pfeifer returning a response instance from the action automatically disables auto rendering, so doing so explicitly is redundant. |
# |
Jun 13th 2021, 07:35 |
admad |
More like black fungus in these covid times. |
# |
Jun 12th 2021, 22:39 |
ndm |
@davinci Never echo data from a controller and/or die in it, this completely breaks CakePHP's execution flow, it breaks headers, it can cause data to be cut off, it messes up the testing environment, etc. If you see someone doing that, make them aware that what they are doing is wrong, and that it will bring them 7 years of bad luck... and foot fungus! |
# |
Jun 12th 2021, 19:16 |
kevin.pfeifer |
well `$this->autoRender = false;` prevents the view from being rendering and therefore all your logic is just in the controller |
# |
Jun 12th 2021, 19:07 |
davinci |
ah, so no need to `echo ... exit();` - just return the response. That seems cleaner |
# |
Jun 12th 2021, 18:56 |
kevin.pfeifer |
if its better/worse or something else I have no idea |
# |
Jun 12th 2021, 18:56 |
kevin.pfeifer |
I like doing that ```$response = $this->getResponse(); $this->autoRender = false; return $response->withType( 'application/json' ) ->withStringBody( json_encode( $results ) );``` |
# |
Jun 12th 2021, 18:54 |
davinci |
I've always used a view, but see someone using an exit, and thought... hmm, maybe that's faster? |
# |
Jun 12th 2021, 18:54 |
davinci |
In an ajax call, is it better to echo json data then exit right from the controller, or use an ajax view? |
# |
Jun 11th 2021, 15:30 |
admad |
Mention that HTTP_HOST was set through phpunit.xml |
# |
Jun 11th 2021, 15:28 |
admad |
@a.vanniel plz open an issue on the cakephp/app repo. |
# |
Jun 11th 2021, 15:28 |
admad |
We could modify that line to first check for HTTP_HOST and use "localhost" only of it's not available. |
# |
Jun 11th 2021, 15:15 |
ndm |
Sure, generally these settings would allow that, but CakePHP does what CakePHP does. Respecting those configs would probably cause a lot of trouble with people that touch the superglobals directly, being in their apps or in their tests. Anyways, godspeed :upside_down_face: |
# |
Jun 11th 2021, 15:10 |
a.vanniel |
Thanks @ndm! |
# |
Jun 11th 2021, 15:10 |
a.vanniel |
I have commented out the offending line though and now the test succeeds because the expected url was set... |
# |
Jun 11th 2021, 15:10 |
a.vanniel |
At least, that is what I understood of the xml file... |
# |
Jun 11th 2021, 15:09 |
a.vanniel |
Using the phpunit.xml those super globals could be set and thus have the tests approach more closely the sort of real life situations... |
# |
Jun 11th 2021, 15:08 |
ndm |
Probably... I think all the globals for the server request object are being filled with custom data in integration tests, ie the PHP supergobals are not being touched. |
# |
Jun 11th 2021, 15:06 |
a.vanniel |
or it actually defeats the purpose of the server variable as well. |
# |
Jun 11th 2021, 15:06 |
a.vanniel |
It kinda defeats the purpose of the HTTP_HOST environment key in the phpunit.xml I guess. |
# |
Jun 11th 2021, 15:06 |
ndm |
I think there's also places internally in the core where `App.fullBaseUrl` is being overwritten... so, you might not be off the hook if you'd wanted to use your custom host setting. |
# |
Jun 11th 2021, 15:04 |
ndm |
Actually, yes, it's the default :) Didn't remember that one. |