Logs for #cakephp

Page 29 of 36,922, showing 100 records out of 3,692,143 total, starting on record 2,801, ending on 2,900

# At Username Text
# Jun 17th 2021, 13:44 ndm @alamnaryab It should be _relatively_ straightforward, test if the language parameter is present (like the in the URL filter), and if it's not, return a response with a location header that holds the current URL with whatever language you want to redirect to prepended.
# Jun 17th 2021, 13:41 kevin.pfeifer but I would guess if you prefer a more frontend AJAX UX you could look at this https://github.com/ishanvyas22/cakephpvue-spa
# Jun 17th 2021, 13:34 kevin.pfeifer then you will need to render that element with the entity you already have and return that html via ajax
# Jun 17th 2021, 13:33 kevin.pfeifer so you could create an element which represents one row of your table
# Jun 17th 2021, 13:33 kevin.pfeifer I have loads of elements which are re-used over and over inside my template
# Jun 17th 2021, 13:32 kevin.pfeifer elements are reusable parts you use in your template https://book.cakephp.org/4/en/views.html#elements
# Jun 17th 2021, 13:32 dantedantas Elements? Sorry, I dont know what do you talk about. :(
# Jun 17th 2021, 13:31 dantedantas Maybe I could run a query, collect the result and create the HTML code and send it back.
# Jun 17th 2021, 13:31 kevin.pfeifer you know what “elements” are in cakephp?
# Jun 17th 2021, 13:30 dantedantas Like this it works.
# Jun 17th 2021, 13:30 dantedantas I am not sure how to do it, or what should be the best way.
# Jun 17th 2021, 13:26 kevin.pfeifer but how should cakephp know that you now want to render your entity in your ajax function with that HTML?
# Jun 17th 2021, 13:25 kevin.pfeifer yes that is present in your index.php
# Jun 17th 2021, 13:25 kevin.pfeifer I never use AJAX functions like that because it is (in my opinion) too much data being sent via AJAX. I only send the data that is being “added/changed” and the HTML is being copied on the clientside inside the JS
# Jun 17th 2021, 13:25 dantedantas This is how I show it now:'
# Jun 17th 2021, 13:23 dantedantas Here is where I show the result. If I could send back a formated HTML code, could be better.
# Jun 17th 2021, 13:23 kevin.pfeifer and where should cakephp get that html from? you only have an entity in that controller, not a rendered template
# Jun 17th 2021, 13:21 dantedantas Could be better. A Html.
# Jun 17th 2021, 13:21 kevin.pfeifer do you expect to get a formatted HTML back?
# Jun 17th 2021, 13:20 dantedantas No. :) Maybe, could you have an example of how to format it?
# Jun 17th 2021, 13:20 alamnaryab I am trying to see documentation how to capture request in middleware and append default language param if not available
# Jun 17th 2021, 13:17 kevin.pfeifer yes, do you expect something different?
# Jun 17th 2021, 13:16 dantedantas The result.
# Jun 17th 2021, 13:16 dantedantas Is already.
# Jun 17th 2021, 13:15 kevin.pfeifer
# Jun 17th 2021, 13:14 kevin.pfeifer have you changed your AJAX request to GET?
# Jun 17th 2021, 13:14 dantedantas Hi Kevin. Thank you for your feedback. It looks much better. :) The 'IF' condition still doesnt work.
# Jun 17th 2021, 13:12 ndm I see, looks like they're supported in 4.next
# Jun 17th 2021, 13:06 admad Maybe, a while back I updated the router classes to support brace style everywhere (and check for those first)
# Jun 17th 2021, 13:05 ndm Maybe because brace style placeholders aren't supported, only the colon ones work.
# Jun 17th 2021, 13:04 ndm @alamnaryab That is the expected behavior, the URL filter only persists the language parameter if there is one present in the request. You could add a default or inferred (from the request's `Accept-Language` header) language in the URL filter, or possibly the better solution, use a middleware to redirect to a URL with a language parameter being added to the path, so that you don't have one and the same URL serving different content.
# Jun 17th 2021, 12:58 admad I was mistaken about not being able to use placeholder as scope :) There was probably some other reason why I didn't/couldn't use them for my i18n routes and misremembered.
# Jun 17th 2021, 12:53 alamnaryab @ndm it is all working fine as long the URL has language param but without language param is says missing param
# Jun 17th 2021, 12:22 ndm Then I misunderstood, I thought your problem was the other way around with 4.x, ie a string _not_ working. Converting the data to a string with `http_build_query()` should be fine, it's what happens internally too.
# Jun 17th 2021, 12:20 alamnaryab @ndm This is working perfectly. You are the hero. :thumbsup:
# Jun 17th 2021, 12:08 ndm @alamnaryab Go from here. If you run into errors, don't jump to using other methods until you have a firm grasp on why things are failing and how the problem could be solved, otherwise you'll never get anywhere with it, as you're just jumping from one problem to the next. ```$routes->scope('/:language', function (RouteBuilder $routes) { $routes->prefix('Admin', function (RouteBuilder $routes) { $patterns = ['language' =>
# Jun 17th 2021, 12:08 slackebot 'en|ar']; $routes ->connect('/', ['controller' => 'Users', 'action' => 'login']) ->setPatterns($patterns); $routes ->connect('/:controller', ['action' => 'index']) ->setPatterns($patterns); $routes ->connect('/:controller/:action/*', []) ->setPatterns($patterns); }); }); $routes->scope('/:language', function (RouteBuilder $builder) {
# Jun 17th 2021, 12:08 slackebot $patterns = ['language' => 'en|ar']; $builder ->connect('/', ['controller' => 'Clients', 'action' => 'index']) ->setPatterns($patterns); $builder ->connect('/:controller', ['action' => 'index']) ->setPatterns($patterns); $builder ->connect('/:controller/:action/*') ->setPatterns($patterns); }); \Cake\Routing\Router::addUrlFilter( function (array $params,
# Jun 17th 2021, 12:08 slackebot \Cake\Http\ServerRequest $request) { if ( $request->getParam('language') andand !isset($params['language']) ) { $params['language'] = $request->getParam('language'); } return $params; } );```
# Jun 17th 2021, 12:06 alamnaryab I used that plugin still I am getting almost same errors I have attached my updated routes.php debugger/routes tab snapshot and error message
# Jun 17th 2021, 11:58 k4t I hope there are no downsides of this
# Jun 17th 2021, 11:58 k4t and it looks like this is the only solution for CakePHP 3.1.14
# Jun 17th 2021, 11:57 k4t for me it is only working when I convert my $data array into string
# Jun 17th 2021, 11:49 ndm It works _despite_ doing that. I though that was what you were trying to do, as you've pointed to the `is_string()` check, and even mentioned using a string instead of an array?
# Jun 17th 2021, 11:46 k4t it is workign for you becuase as $date parameter you passed string not an array
# Jun 17th 2021, 11:40 kevin.pfeifer 1. Your AJAX Function in your 2. screenshot uses POST and not GET as a Method 2. I was wrong, `->contain()` doesn’t work with `->get()` you need to specify it like that ```$this->Vieworg->get( $id, [ 'contain' => [ 'Viewadr' ], ] );```
# Jun 17th 2021, 11:35 alamnaryab I have not checked, let me see now
# Jun 17th 2021, 11:35 dantedantas Hi Kevin, here you can see my ajaxAction. And you have also my Ajax-javascript function. I have 2 issues. The first is that I have no idea how to show/catch the result and show it on the other screen. The other issue is if I may have as a responsa an HTML code. I would like to format the result into a table and send it back. Thank you.
# Jun 17th 2021, 11:35 alamnaryab I have not checked, let me see now
# Jun 17th 2021, 11:34 alamnaryab there is no special routes, only default root and admin prefix
# Jun 17th 2021, 11:33 alamnaryab if it is difficult for you people to look at my dummy project at github please convert this routes.php for me ```use Cake\Routing\Route\DashedRoute; use Cake\Routing\RouteBuilder; $routes->setRouteClass(DashedRoute::class); $routes->scope('/', function (RouteBuilder $builder) { $builder->connect('/', ['controller' => 'Articles', 'action' => 'index']); $builder->fallbacks(); }); $routes->prefix('Admin',
# Jun 17th 2021, 11:33 slackebot function (RouteBuilder $routes) { $routes->fallbacks(DashedRoute::class); }); ```
# Jun 17th 2021, 11:32 alamnaryab I thank you people @ndm @admad @kevin.pfeifer but what ever I am trying I am getting errors on all or admin prefix, that's why I created dummy project to just convert default routes.php for me that works with language in url.
# Jun 17th 2021, 11:31 ndm It works for me, a quick test shows that the supplied content type is being used: ```public function testContentTypeWithStringData() { $contentType = 'application/x-www-form-urlencoded; charset=utf-8'; $adapter = $this ->getMockBuilder(Stream::class) ->onlyMethods(['send']) ->getMock(); $adapter ->expects($this->once()) ->method('send') ->with($this->callback(function
# Jun 17th 2021, 11:31 slackebot ($request) use ($contentType) { $this->assertEquals($contentType, $request->getHeaderLine('Content-Type')); return true; })) ->will($this->returnValue([new Response()])); $http = new Client([ 'host' => 'cakephp.org', 'adapter' => $adapter, ]); $http->post('/projects/add', 'string data', [ 'headers' => [ 'Content-Type' => $contentType ],
# Jun 17th 2021, 11:31 slackebot ]); }```
# Jun 17th 2021, 11:25 admad I hope this doesn't mean now I am on the hook for sorting out his problem :P
# Jun 17th 2021, 11:24 admad @alamnaryab have you checked out https://github.com/ADmad/cakephp-i18n#i18nroute?
# Jun 17th 2021, 11:13 k4t it will work only when you do ```$this->_httpClient->post($url, http_build_query($data), [ 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8'] ]);``` which is yeah... a bit weird
# Jun 17th 2021, 11:12 k4t It will work only if you pass $data attribute as a string not an array
# Jun 17th 2021, 10:47 ndm @alamnaryab The example I've posted on SO works fine, I've tested it, the errors that you were receiving were because of wrong URL arrays. Again, if you want this to work without having to supply the `language` key in all URL arrays, then you need to persist it! https://book.cakephp.org/4/en/development/routing.html#creating-persistent-url-parameters
# Jun 17th 2021, 10:45 ndm @k4t It should work fine in 4.x. That `is_string() ...` code won't do anything if you're providing the header as shown in your snippet.
# Jun 17th 2021, 09:50 conehead @paolo.bragagni Use form templates
# Jun 17th 2021, 09:36 kevin.pfeifer :,) ok
# Jun 17th 2021, 09:35 dantedantas I sent the text by mistake. I cant press "Enter". I will finish the mensage. Thank you. :)
# Jun 17th 2021, 09:34 kevin.pfeifer an you should get ``` { 'data' => 'hello' }```
# Jun 17th 2021, 09:33 kevin.pfeifer try setting ``` return $response->withType( 'application/json' ) ->withStringBody( json_encode( [ 'data' => 'hello' ] ) );```
# Jun 17th 2021, 09:33 kevin.pfeifer yes? Don’t you expect that?
# Jun 17th 2021, 09:32 dantedantas Hi Kevin, Guten Morgen. Please, could you help me a little bit more with this issue? I tried what you wrote above, but without success. If I try to access the action, I am getting the screen bellow:
# Jun 17th 2021, 08:45 k4t as I can not append charst=utf-8 to Content-Type header we have problems with encoding sometimes
# Jun 17th 2021, 08:44 k4t I do not understand why there is that is_string($data) in the if which breaks it
# Jun 17th 2021, 08:38 k4t in the latest Cake it will also not work because of: https://github.com/cakephp/cakephp/blob/4.2.7/src/Http/Client.php#L574
# Jun 17th 2021, 08:09 k4t https://github.com/cakephp/cakephp/blob/3.1.14/src/Network/Http/Adapter/Stream.php#L185
# Jun 17th 2021, 08:07 paolo.bragagni how can I put some bootstrap buttons in $this->Form->input ?
# Jun 17th 2021, 08:06 paolo.bragagni in form helper no more after and before ??
# Jun 17th 2021, 08:02 k4t It it generally caused by: https://github.com/cakephp/cakephp/blob/3.x/src/Http/Client/FormData.php#L227
# Jun 17th 2021, 07:58 k4t @admad
# Jun 17th 2021, 07:35 k4t How can I solve this?
# Jun 17th 2021, 07:35 k4t Hi all, in CakePHP 3.1.x I use Cake HTTP Client and I have to set following header for all my post requests: application/x-www-form-urlencoded;charset=utf-8. Here is how I am doing it: ```$response = $this->_httpClient->post($url, $data, [ 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8'] ]);``` Unfortunatelly this does not work as CakePHP before sending request is replacing Content-Type header
# Jun 17th 2021, 07:35 slackebot with "application/x-www-form-urlencoded" even if I set it by myself like in my example.
# Jun 17th 2021, 07:26 alamnaryab Good Morning I am facing issue with routing since last 2 weeks. also posted at stackoverflow as well as at discourse.cakephp.org I got responses but none worked for me, I am new with Cakephp4 that's why I am not sure when what to debug to fix this issue. some people says application.php has error some say check URL array(i don't know how) in slack also @kevin.pfeifer tried his best to help but we caould not found the
# Jun 17th 2021, 07:26 slackebot solution. I thought I will create basic CMS project available at cakephp website, with Authentication plugin, admin prefix and multi language implementation. that is available at https://github.com/alamadcs/cake4-routing-problem please help me out in this Currently the current language is being saved in Session not URL. I want it to be in URL, I have also written code to handle it ( commented at AppController/BeforeFilter() ) plz help
# Jun 17th 2021, 07:26 slackebot me with just config/routing.php to make urls as below www.domain.com/en/* www.domain.com/en/admin/*
# Jun 17th 2021, 07:13 conehead Does anyone know if/how it is possible to disable translations in unit tests?
# Jun 17th 2021, 07:13 conehead Good morning everyone.
# Jun 17th 2021, 05:30 dereuromark https://github.com/dereuromark/cakephp-queue/blob/master/src/Plugin.php#L38 works for me.
# Jun 17th 2021, 00:17 japerlman how can I troubleshoot/diagnose an issue with the friendsofcake CRUD component for json api on cake 3.x I'm using a REST client and when I set the header for application/json I get 'null' as the only thing back on my GET but if I remove the header I get the normal cakephp view as expected. So I'm thinking there's an issue in the auto-magic of the CRUD component but I really have no idea where to start
# Jun 17th 2021, 00:00 vinicius.big I was looking for a cakephp way to do it, but I think a `class_exists()` will fit here
# Jun 16th 2021, 23:45 vinicius.big thinking here that probably I will have to install Bake even for production
# Jun 16th 2021, 23:40 vinicius.big Hello! How can I *disable* a command inside my plugin when in production mode? I've created a custom bake command in order to bake custom stuff on my project. I'm extending the `AllCommand` from bake. and the class in `src/Command/AllCommand.php` is using `use Bake\Command\AllCommand` But, on production, the Bake plugin is not installed, and I'm getting this class not found error. Is there a way to get around this?
# Jun 16th 2021, 20:25 joey.mukherjee Using a CakePHP union from database, I am not getting all of my "contain"ed tables. I am only getting the first one that is contained. If I reverse the union, I get the other one. Is there a way I can get them all? Here's my union: $reviewers = $obs->union ($tests); If I reverse the "tests" and "obs", I get the other tables information which is correct, but I want them all regardless of the order in the union. Any
# Jun 16th 2021, 20:25 slackebot ideas? I can post more code if it helps, but I'm trying to keep it simple.
# Jun 16th 2021, 20:21 kevin.pfeifer if there is a `composer.lock` file present the command `composer install` will ignore the version strings in your `composer.json` and just install the versions which are set in the `composer.lock` file but if you don't have a `composer.lock` file then it will generate a new one with the newest versions currently available (according to the version strings)
# Jun 16th 2021, 20:19 kevin.pfeifer see https://getcomposer.org/doc/articles/versions.md#stability-constraints for what the different version strings are
# Jun 16th 2021, 20:18 kevin.pfeifer the short gist of it composer.json is the "what versions of software would I like to have" file composer.lock gets generated after executing `composer install` based on the conditions set in the composer.json You can basically perform a `composer update` anytime you want. It then checks what versions are actually installed currently in your system (via the composer.lock file) and the checks if there are newer version
# Jun 16th 2021, 20:18 slackebot present (which are still valid to your constraints set in composer.json)
# Jun 16th 2021, 20:17 japerlman I see .lock I think it's a file being used by a process running I thought it was stale and left over
# Jun 16th 2021, 20:16 japerlman I don't and I deleted my composer.lock to get around the last error I was getting so I probably messed it up
# Jun 16th 2021, 20:09 kevin.pfeifer you know how composer.json and composer.lock are related?
# Jun 16th 2021, 20:09 kevin.pfeifer just a composer.json doesn't allow you to use that command