Logs for #cakephp

Page 34 of 36,922, showing 100 records out of 3,692,143 total, starting on record 3,301, ending on 3,400

# At Username Text
# Jun 11th 2021, 15:04 ndm Good question....
# Jun 11th 2021, 15:03 a.vanniel Is that per default? Or do I have to start kicking one of my colleagues here?
# Jun 11th 2021, 15:02 a.vanniel wow.
# Jun 11th 2021, 15:02 a.vanniel wait... I found it in the tests\bootstrap.php file...
# Jun 11th 2021, 15:02 a.vanniel I did a debug of env('HTTP_HOST') in the controller I am testing and I get this: http://pearson.presenter.local so that is what it should be,
# Jun 11th 2021, 15:00 a.vanniel bootstrap_cli.php does not overwrite it.. that line is commented out it only contains the lines to configure the debug and error log file names.
# Jun 11th 2021, 14:59 ndm So `env('HTTP_HOST)` returns the expected result? Then maybe check if the option is being overwritten in `bootstrap_cli.php`
# Jun 11th 2021, 14:58 a.vanniel FYI the fullBaseUrl setting in the config file of the application is set to false... so this should use the HTTP_HOST
# Jun 11th 2021, 14:57 a.vanniel welll. this is rather weird... $ref is set to the url I provided, however the $base is set to http://localhost eventhough I have set this in the phpunit.xml: ```<server name="HTTP_HOST" value="http://pearson.presenter.local" />``` and this actually does work ... so I wonder why $base would be set to localhost ... and since the default is to return a local address... well, this probably fails since the base is different...
# Jun 11th 2021, 14:54 ndm And I guess debug `$ref` too while you're at it, just to make sure a value is actually set.
# Jun 11th 2021, 14:53 ndm Ok, now try a `debug($base)` in the `referer()` method to see what is being expected.
# Jun 11th 2021, 14:51 a.vanniel I know, environment should not be set since it is a header setting... but just to be sure :)
# Jun 11th 2021, 14:51 a.vanniel Just so I was sure I had set all of them, I did these right before the $this->get() in the test: ```$this->configRequest([ 'headers' => [ 'HTTP_REFERER' => 'http://pearson.presenter.local/mediafiles/view/6', 'REFERER' => 'http://pearson.presenter.local/mediafiles/view/6', ], 'environment' =>[ 'HTTP_REFERER' => 'http://pearson.presenter.local/mediafiles/view/6', 'REFERER' =>
# Jun 11th 2021, 14:51 slackebot 'http://pearson.presenter.local/mediafiles/view/6', ], ]);``` still the $this->referer() in the controller to be tested, results in '/'
# Jun 11th 2021, 14:50 ndm Well do both, an absolute and a header without `HTTP_`. Then make sure that the full URL that you are providing starts with what is set for `App.fullBaseUrl`. It might be different to what you expect in your tests.
# Jun 11th 2021, 14:47 a.vanniel it keeps giving me '/' as the referer...
# Jun 11th 2021, 14:47 a.vanniel Unfortunately setting the referer key to the absolute url did not seem to change anything $this->referer() is returning in the controller.
# Jun 11th 2021, 14:45 kevin.pfeifer we literally talked about that yesterday :)
# Jun 11th 2021, 14:45 ndm Well, maybe not in any case... but at least when `App.fullBaseUrl` is set to a URL.
# Jun 11th 2021, 14:45 slackebot <kevin.pfeifer>
# Jun 11th 2021, 14:44 ndm Don't use the `HTTP_` prefix in headers, it will be added automatically where required. That being said, passing the full name via `environment` should work too, but in any case you need to use absolute URLs.
# Jun 11th 2021, 14:40 a.vanniel I at first tried this: ```$this->configRequest([ 'headers' => ['HTTP_REFERER' => '/mediafiles/view/6'], ]);``` but that did not change anything and after digging in how cake determines the $this->referer()I figured it could be an environment setting ... seeing this is inside the ServerRequest::referer() method: ```public function referer(bool $local = true): ?string { $ref = $this->getEnv('HTTP_REFERER');```
# Jun 11th 2021, 14:37 greg138 I think you want to set the Referer header rather than environment?
# Jun 11th 2021, 14:19 a.vanniel Good afternoon everyone. Does anyone potentially know how to set the http_referer for unit testing? I have this code that acts differently depending on the origin (referrer) and I though this would be the sollution but it does not seem to work: ```$this->configRequest([ 'environment' => ['HTTP_REFERER' => '/mediafiles/view/6'], ]);``` instead the default '/' remains set as the referrer.
# Jun 11th 2021, 12:44 kevin.pfeifer I personally would love some sort of hook or event system added to the default form and html helpers to adjust the outputted HTML but never had the time to jump into it
# Jun 11th 2021, 12:43 kevin.pfeifer sure, thats the most flexible one but the most tedious one :)
# Jun 11th 2021, 12:43 tomrwaller Looks like I have some reading to do. Thanks @kevin.pfeifer. I also just tried adding the class=>form-control to the text controls in my views and that works too. It's a little more code on the view but gets me out of a pickle for now.
# Jun 11th 2021, 12:19 kevin.pfeifer the “problem” with that approach is, that you need to manually adjust your overwritten functions if the “core” formhelper makes updates/changes
# Jun 11th 2021, 12:12 kevin.pfeifer if you dont use FormHelper as a class you will need to specify that in your `src/View/AppView.php` initialize function via ``` $this->loadHelper( 'Form', [ 'templates' => 'app_form', // will load templates from config/app_form.php 'className' => 'MyForm' ] );```
# Jun 11th 2021, 12:11 kevin.pfeifer its the same for cakephp 4
# Jun 11th 2021, 12:11 kevin.pfeifer basically that https://stackoverflow.com/questions/57730430/cakephp-3-how-to-extend-an-helper
# Jun 11th 2021, 12:10 tomrwaller I didn't! Although I suspected there is a whole bunch you can do that I have no clue about! Do you have a link or search term I can look for in the book maybe?
# Jun 11th 2021, 12:08 kevin.pfeifer sure :) Do you know that you can extend basically any class and use that instead of the “core” one to have some custom logic in there?
# Jun 11th 2021, 12:07 tomrwaller Sorry! I think this is my lack of knowledge shining through :) I have a Form Template not Helper.
# Jun 11th 2021, 12:06 kevin.pfeifer or am I not aware of some feature that the Helpers can do with these form templates :thinking_face:
# Jun 11th 2021, 12:00 kevin.pfeifer no i mean do you have `src/View/Helper/MyFormHelper.php` which extends the base FormHelper
# Jun 11th 2021, 12:00 tomrwaller Yes I guess I could pass the class through the control - thanks for the tip! I do have a custom FormHelper already, albeit very basic! `<?php`     `return [`         `'checkboxFormGroup'   => '<div class="form-check"><div class="checkbox">{{label}}</div></div>',`         `'checkbox'            => '<input type="checkbox" class="form-check-input" name="{{name}}" value="{{value}}"
# Jun 11th 2021, 12:00 slackebot {{attrs}} />',`         `'checkboxWrapper'     => '<div class="form-check">{{label}}</div>',`         `'inputContainer'      => '<div class="form-group mb-3">{{content}}<span class="help form-text text-muted small"><i class="fas fa-fw fa-question-circle"></i>andnbsp{{help}}</span></div>',`         `'input'               => '<input type="{{type}}" name="{{name}}" {{attrs}}
# Jun 11th 2021, 12:00 slackebot />',`         `'label'               => '<label {{attrs}} class="form-label text-primary" style="text-transform: uppercase">{{text}}</label>',`         `'select'              => '<select class="form-control" {{attrs}} name={{name}}>{{content}}</select>',`         `'selectMultiple'      => '<select class="form-select" multiple {{attrs}}
# Jun 11th 2021, 12:00 slackebot name={{name}}[]>{{content}}</select>',`         `'error'               => '<p class="text-danger">{{content}}</p>',`         `'textarea'            => '<div class="form-group"><textarea class="form-control" name="{{name}}" {{attrs}}>{{value}}</textarea></div>',`         `'button'              => '<div class="form-group"><div><button class="btn btn-primary"
# Jun 11th 2021, 12:00 slackebot {{attrs}} type="submit">{{text}}</button></div></div>',`         `'inputContainerError' => '<div class="form-group has-error" {{required}}>{{content}}</div>{{error}}',`     `]` `?>`
# Jun 11th 2021, 11:59 kevin.pfeifer I am not aware that you ccan do conditional logic purely in form templates
# Jun 11th 2021, 11:58 kevin.pfeifer i would guess you would have to add that logic to the `control()` (or whatever function you are using in your template) So do you have a custom FormHelper already?
# Jun 11th 2021, 11:52 tomrwaller So I have one for input: 'input' => '<input type="{{type}}" name="{{name}}" {{attrs}} />', This applies to both text input and range input though. I want text input to have a class of form-control in order for it to be Bootstrap 5 formatted. If I add form-control here, it borks my range inputs.
# Jun 11th 2021, 11:51 kevin.pfeifer so you just need a class with the type of the input?
# Jun 11th 2021, 11:47 tomrwaller Quick follow up question on Form Helpers if I may - is there anyway in the template to differentiate between a text input and say a range input? If I add form-control class to the input template, it messes up the range, and if I remove it, range works but text box doesn't.
# Jun 11th 2021, 10:50 paolo.bragagni I pointed my debug breackpoint in the fetch action and I didnt notice the error
# Jun 11th 2021, 10:50 paolo.bragagni but (I dont know why) if I access via ajax it goes to beforefind
# Jun 11th 2021, 10:49 paolo.bragagni if I browse directly it doesnt went to beforefind and I got debugging
# Jun 11th 2021, 10:48 paolo.bragagni there was an erro in my controller beforefind
# Jun 11th 2021, 10:48 kevin.pfeifer ok, then I ran into another problem with my app where i had to manually add that token :shrug:
# Jun 11th 2021, 10:48 paolo.bragagni yes it works
# Jun 11th 2021, 10:47 slackebot <paolo.bragagni>
# Jun 11th 2021, 10:46 kevin.pfeifer the CsrfMiddleware is a security feature which is enabled by default so it would be pretty bad if you disable it just for that ^^
# Jun 11th 2021, 10:46 kevin.pfeifer does it still work?
# Jun 11th 2021, 10:46 kevin.pfeifer well if you enable it now
# Jun 11th 2021, 10:46 paolo.bragagni trying to enable?
# Jun 11th 2021, 10:46 paolo.bragagni yes
# Jun 11th 2021, 10:45 kevin.pfeifer do you still have the CsrfMiddleware disabled?
# Jun 11th 2021, 10:45 kevin.pfeifer but!
# Jun 11th 2021, 10:45 kevin.pfeifer nice
# Jun 11th 2021, 10:45 slackebot <paolo.bragagni>
# Jun 11th 2021, 10:45 paolo.bragagni thenks kevin
# Jun 11th 2021, 10:27 wizardfix Many thanks @kevin.pfeifer I'll try that. :)
# Jun 11th 2021, 10:26 kevin.pfeifer so if you need to stay on 3.5.17 you can add that try-catch block in your `/app/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php`
# Jun 11th 2021, 10:23 kevin.pfeifer well according to https://stackoverflow.com/questions/32239205/php-pdo-hide-error-message-when-failed-connecting-to-mysql-server Its basically an exception from the PDO Class which needs to be catched via a try-catch block.
# Jun 11th 2021, 10:20 wizardfix Haha yes I know @kevin.pfeifer the powers that be are nervous of upgrading...
# Jun 11th 2021, 10:18 kevin.pfeifer @wizardfix thats quite the old cakephp version ,:)
# Jun 11th 2021, 10:17 kevin.pfeifer @paolo.bragagni json should be returned like so ```$response = $this->getResponse(); $this->autoRender = false; return $response->withType( 'application/json' ) ->withStringBody( json_encode( $results ) );```
# Jun 11th 2021, 10:15 wizardfix @kevin.pfeifer '3.5.17'
# Jun 11th 2021, 10:15 paolo.bragagni is not possible anymore?
# Jun 11th 2021, 10:15 paolo.bragagni in my old controller I return json with echo json_encode($results);
# Jun 11th 2021, 10:15 paolo.bragagni btu noew I have another question..
# Jun 11th 2021, 10:14 paolo.bragagni there was an error in my old autocontroller
# Jun 11th 2021, 10:14 paolo.bragagni steps ahead
# Jun 11th 2021, 09:59 kevin.pfeifer what is the error / message you get back from your failed ajax request @paolo.bragagni
# Jun 11th 2021, 09:55 paolo.bragagni no. something missing
# Jun 11th 2021, 09:46 kevin.pfeifer @wizardfix what cakephp version are you using?
# Jun 11th 2021, 09:29 paolo.bragagni check again :)
# Jun 11th 2021, 09:29 paolo.bragagni probably is in my js
# Jun 11th 2021, 09:26 paolo.bragagni no. doesnt work
# Jun 11th 2021, 09:24 wizardfix Hi all... just wondering, is there an easy way to stop CakePHP partially logging passwords in stack traces? Like this: ``````
# Jun 11th 2021, 09:23 paolo.bragagni azz
# Jun 11th 2021, 09:22 kevin.pfeifer by "it" i mean the whole ``` //->add(new CsrfProtectionMiddleware([ // 'httponly' => true, //]));```
# Jun 11th 2021, 09:20 kevin.pfeifer ```'httponly' => false,``` doesn't deactive the middleware you have to comment it out to check if its the CSRF Protection which prevents you ajax
# Jun 11th 2021, 09:19 paolo.bragagni (but)
# Jun 11th 2021, 09:19 paolo.bragagni put to false bau same behaviour
# Jun 11th 2021, 09:11 kevin.pfeifer https://github.com/cakephp/app/blob/master/src/Application.php#L103
# Jun 11th 2021, 09:11 kevin.pfeifer but you do have the CsrfMiddleware active
# Jun 11th 2021, 09:10 paolo.bragagni no
# Jun 11th 2021, 09:10 kevin.pfeifer in your ajax call
# Jun 11th 2021, 09:10 kevin.pfeifer do you set the CSRF-Toke header?
# Jun 11th 2021, 09:10 paolo.bragagni (it is an autocomplete function that i use for fill some search inputs)
# Jun 11th 2021, 09:08 paolo.bragagni and if I fire manually the url I go to right controller
# Jun 11th 2021, 09:08 paolo.bragagni GET "https://cakephp.local/cake4/cake4/autocomplete/fetch/Libri/titolo?term=la".
# Jun 11th 2021, 09:08 paolo.bragagni I see
# Jun 11th 2021, 09:08 paolo.bragagni if I debug the ajax call
# Jun 11th 2021, 09:07 paolo.bragagni it worked in cake 2 :S
# Jun 11th 2021, 09:05 paolo.bragagni probably
# Jun 11th 2021, 09:05 paolo.bragagni hihi