# |
Jul 27th 2021, 14:00 |
cnizzardini |
maybe, i haven't messed with 8 yet |
# |
Jul 27th 2021, 14:00 |
brandon |
`mixed` would likely work then, right? |
# |
Jul 27th 2021, 14:00 |
cnizzardini |
they did, `static` and `mixed` |
# |
Jul 27th 2021, 14:00 |
brandon |
I haven't been following 8 development - not sure |
# |
Jul 27th 2021, 13:59 |
cnizzardini |
@brandon didn't they add a new return type in php 8? |
# |
Jul 27th 2021, 13:58 |
paolo.bragagni |
where I can define myrule ? |
# |
Jul 27th 2021, 13:58 |
brandon |
According to this, https://php.watch/versions/8.0/union-types, void type is not allowed anymore @cnizzardini |
# |
Jul 27th 2021, 13:58 |
paolo.bragagni |
$validator->add('descrizione', 'custom', [ 'rule' => 'myrule', 'message' => 'The title is not valid' ]); |
# |
Jul 27th 2021, 13:57 |
paolo.bragagni |
hi how to add my own validator? read the docs but.. emh... |
# |
Jul 27th 2021, 13:57 |
brandon |
Looks like you can have more than 2... https://wiki.php.net/rfc/union_types_v2 |
# |
Jul 27th 2021, 13:57 |
cnizzardini |
wonder if `Response|null|void` will work in php8 |
# |
Jul 27th 2021, 13:55 |
cnizzardini |
all the examples i've seen show two, e.g. `string|null` |
# |
Jul 27th 2021, 13:55 |
brandon |
That worked. Thanks, guys. |
# |
Jul 27th 2021, 13:54 |
cnizzardini |
or is it just two? |
# |
Jul 27th 2021, 13:54 |
cnizzardini |
curious if union types will allow listing three responses? |
# |
Jul 27th 2021, 13:53 |
dereuromark |
@brandon I use Response|null|void still everywhere in docblock, which is fine |
# |
Jul 27th 2021, 13:51 |
cnizzardini |
```includes: - phpstan-baseline.neon parameters: level: 6 checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false treatPhpDocTypesAsCertain: false bootstrapFiles: - tests/bootstrap.php paths: - src earlyTerminatingMethodCalls: Cake\Console\Shell: - abort``` |
# |
Jul 27th 2021, 13:51 |
cnizzardini |
I run phpstan with these settings and don't get errors with that |
# |
Jul 27th 2021, 13:50 |
cnizzardini |
``` /** * @return \Cake\Http\Response|null|void Renders view */ public function index()``` |
# |
Jul 27th 2021, 13:50 |
cnizzardini |
Can you try this: |
# |
Jul 27th 2021, 13:48 |
slackebot2 |
$this->getRequest()->getAttribute('paging')[$this->name]['pageCount']]]); } }``` |
# |
Jul 27th 2021, 13:48 |
brandon |
It is a pretty standard action too. ``` /** * Index method * * @return Response|null */ public function index(): ?Response { $query = $this->Systems->find()->contain(['AssetTags']); try { $this->set('systems', $this->paginate($query)); } catch (NotFoundException $e) { return $this->redirect(['action' => 'index', '?' => ['page' => |
# |
Jul 27th 2021, 13:44 |
brandon |
But like I said, pages are now failing to load so something is wrong (assuming with the upgrade). ```Return value of Inventory\Controller\SystemsController::index() must be an instance of Cake\Http\Response or null, none returned``` |
# |
Jul 27th 2021, 13:43 |
brandon |
@admad I'm aware and I love it now that I know it exists. I guess I am hellbent on maintaining clean code by making sure phpstan and phpcs come back clean. |
# |
Jul 27th 2021, 13:43 |
admad |
(unless it reports a legitimate error) |
# |
Jul 27th 2021, 13:42 |
admad |
don't waste time trying to make tools happy |
# |
Jul 27th 2021, 13:42 |
admad |
@brandon phpstan is supposed to work for you, not vice versa. |
# |
Jul 27th 2021, 13:40 |
brandon |
@dereuromark if I set the phpdoc for a controller action to anything other than Response|null, things like phpstan complain. And now pages will not load unless I return something (I've been returning null. This is new since upgrading to 4.x). |
# |
Jul 27th 2021, 11:12 |
paolo.bragagni |
:( |
# |
Jul 27th 2021, 11:12 |
paolo.bragagni |
{{ dump(validation) }} there is nothing about associated fields |
# |
Jul 27th 2021, 10:55 |
paolo.bragagni |
I have to modify my table.twig to add it? |
# |
Jul 27th 2021, 10:53 |
paolo.bragagni |
in my validator |
# |
Jul 27th 2021, 10:53 |
paolo.bragagni |
but in my DischiTable theres not a ->notEmpty('author_id') |
# |
Jul 27th 2021, 10:52 |
paolo.bragagni |
|
# |
Jul 27th 2021, 10:52 |
paolo.bragagni |
AND it shows in bold |
# |
Jul 27th 2021, 10:50 |
paolo.bragagni |
null for filed author_id is set to false in DB |
# |
Jul 27th 2021, 10:47 |
dereuromark |
make sure to set null=>false here in your schema |
# |
Jul 27th 2021, 10:45 |
paolo.bragagni |
where does it get the {%- if fieldData.null %} variable? |
# |
Jul 27th 2021, 10:44 |
paolo.bragagni |
It shows as it should not be empty but theres not validator? |
# |
Jul 27th 2021, 10:43 |
paolo.bragagni |
it works, but why it not puts forr defaults while I've baked the Table? |
# |
Jul 27th 2021, 10:39 |
dereuromark |
so you dont want it to be empty? then set up the validation for it to fail here before it tries to save.# |
# |
Jul 27th 2021, 10:37 |
paolo.bragagni |
and not an sql error.. !! |
# |
Jul 27th 2021, 10:37 |
paolo.bragagni |
|
# |
Jul 27th 2021, 10:36 |
paolo.bragagni |
yes but I'd like to obtain a nice popup like this |
# |
Jul 27th 2021, 10:33 |
dereuromark |
optional means: DB field is DEFAULT NULL etc |
# |
Jul 27th 2021, 10:32 |
dereuromark |
you cannot omit the author if you told the db that this isn't a possibility. either you decide for being optional or you don't :) |
# |
Jul 27th 2021, 10:30 |
paolo.bragagni |
SQLSTATE[HY000]: General error: 1364 Field 'autore_id' doesn't have a default value |
# |
Jul 27th 2021, 10:29 |
paolo.bragagni |
if I omit title I got the popup, if I omit the Author (select field) I got a DB error |
# |
Jul 27th 2021, 10:29 |
paolo.bragagni |
|
# |
Jul 27th 2021, 10:12 |
paolo.bragagni |
solved |
# |
Jul 27th 2021, 09:27 |
paolo.bragagni |
{{ action }} ?? |
# |
Jul 27th 2021, 09:26 |
paolo.bragagni |
how to get the name of the action that is baking in twig? |
# |
Jul 27th 2021, 08:17 |
dereuromark |
No, it can also be |void still |
# |
Jul 27th 2021, 06:29 |
brandon |
I can't seem to find this documented anywhere - controller actions seem to require `return null;` at the end if you aren't returning a Response to keep the code clean. No examples show this return on actions. What are the suggestions? ```Return value of Inventory\Controller\SystemsController::index() must be an instance of Cake\Http\Response or null, none returned``` |
# |
Jul 27th 2021, 01:05 |
cnizzardini |
ugh: https://github.com/slevomat/coding-standard/issues/872 |
# |
Jul 27th 2021, 01:02 |
cnizzardini |
Any idea why? |
# |
Jul 27th 2021, 01:02 |
cnizzardini |
```use SwaggerBake\Lib\MediaType\{Generic, HalJson, JsonLd};``` |
# |
Jul 27th 2021, 01:01 |
cnizzardini |
Using cakephp code sniffer i get the following error `| ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Generic.` with grouped use declarations like this: |
# |
Jul 26th 2021, 20:57 |
umer936 |
I think thats what i will end up doing. Thank you! I'm currently reworking the whole thing so if you think of other tips, I can most likely use them. :) |
# |
Jul 26th 2021, 20:51 |
greg138 |
You'd need to do something like `use \App\PlotsController as BasePlotsController;` and then `extend BasePlotsController`. That's nothing to do with Cake, just standard PHP namespacing. |
# |
Jul 26th 2021, 20:42 |
umer936 |
@greg138 That was the original thought but it complains about the controller name being used twice |
# |
Jul 26th 2021, 20:42 |
alamnaryab |
I am inserting records in 3 tables inside a transaction |
# |
Jul 26th 2021, 20:39 |
cnizzardini |
but thats all up to you |
# |
Jul 26th 2021, 20:39 |
cnizzardini |
personally, if you can, i would just support both put/post on edit in your controller action |
# |
Jul 26th 2021, 20:38 |
cnizzardini |
according to the documentation (first link) it uses POST on creates, and PUT on edits |
# |
Jul 26th 2021, 20:37 |
cnizzardini |
are you editing an existing record |
# |
Jul 26th 2021, 20:36 |
alamnaryab |
@cnizzardini `'type' => 'post'` worked but I do not know why it is switching when I am not specifying `'type' => 'post'` |
# |
Jul 26th 2021, 20:33 |
alamnaryab |
I dont know why? |
# |
Jul 26th 2021, 20:33 |
alamnaryab |
I checked HTML on even times of POST it do adds `<input type="hidden" name="_method" value="PUT">` |
# |
Jul 26th 2021, 20:30 |
cnizzardini |
i think you want `'type' => 'post'` instead of using `'method' => 'post'` |
# |
Jul 26th 2021, 20:28 |
cnizzardini |
https://book.cakephp.org/4/en/views/helpers/form.html#options-for-form-creation |
# |
Jul 26th 2021, 20:28 |
cnizzardini |
try this: |
# |
Jul 26th 2021, 20:27 |
cnizzardini |
i believe edit() does a put by default |
# |
Jul 26th 2021, 20:27 |
cnizzardini |
```Since this is an edit form, a hidden input field is generated to override the default HTTP method.``` |
# |
Jul 26th 2021, 20:26 |
cnizzardini |
Scroll to the part where it says |
# |
Jul 26th 2021, 20:26 |
cnizzardini |
For you then |
# |
Jul 26th 2021, 20:26 |
cnizzardini |
https://book.cakephp.org/4/en/views/helpers/form.html#starting-a-form |
# |
Jul 26th 2021, 20:25 |
cnizzardini |
but i know if you create restful resources in routes some routes allow post/put/patch, i think for edit |
# |
Jul 26th 2021, 20:24 |
cnizzardini |
heh well that will not work for me |
# |
Jul 26th 2021, 20:24 |
alamnaryab |
http://localhost/school/guardians/add?student=119 |
# |
Jul 26th 2021, 20:23 |
alamnaryab |
no, not created specific for this method |
# |
Jul 26th 2021, 20:21 |
cnizzardini |
Did you create a route for this? |
# |
Jul 26th 2021, 20:15 |
greg138 |
I know that POST and PUT are generally considered pretty synonymous. |
# |
Jul 26th 2021, 20:15 |
greg138 |
Well, how Cake is interpreting that is done entirely in PHP code that you can debug... |
# |
Jul 26th 2021, 20:14 |
alamnaryab |
i checked network tab is also showing always `post` |
# |
Jul 26th 2021, 20:13 |
greg138 |
If the HTML is always showing the same, check what your browser is sending. |
# |
Jul 26th 2021, 20:07 |
alamnaryab |
HTML is also show post as `<form method="post" ....` |
# |
Jul 26th 2021, 20:06 |
alamnaryab |
how cake php decide if a form is `post` or `put` because I also tried explicitly defining method as `<?= $this->Form->create($entity,['method'=>'post']) ?>` |
# |
Jul 26th 2021, 20:04 |
alamnaryab |
I noticed because on odd times I am receiving flash error message while not on even times I did `debug($this->request)` and check `'REQUEST_METHOD' => 'PUT'` on even time while it is `post` on odd times |
# |
Jul 26th 2021, 19:59 |
greg138 |
The HTML is changing, or you're seeing this in your network tab of developer tools? |
# |
Jul 26th 2021, 19:54 |
alamnaryab |
I noticed on form submit if there is input validation error and I am not correcting it and keep on submitting 1st time `$this->reqest->is('post')` is `true` 2nd time false 3rd time true 4th time false and so on. I checked it is switching to `put` what are possible reasons. |
# |
Jul 26th 2021, 19:46 |
greg138 |
Would it work to have your plugin controller `extend` the base version? |
# |
Jul 26th 2021, 19:46 |
tyler.adam.lazenby |
oh my gosh... thank you |
# |
Jul 26th 2021, 19:44 |
greg138 |
https://book.cakephp.org/3/en/core-libraries/collections.html#sorting: "By default, `SORT_NUMERIC` is used" |
# |
Jul 26th 2021, 19:43 |
tyler.adam.lazenby |
```$collection = new Collection($contact_list->contacts); $sorted = $collection->sortBy(function($contact) { return $contact->first_name; }, SORT_ASC);``` |
# |
Jul 26th 2021, 19:43 |
tyler.adam.lazenby |
still not working |
# |
Jul 26th 2021, 19:42 |
alamnaryab |
Hi in my add action, if there is error once request method is `post` next time `put` it is switching each time. my code is too lengthy by it is as below ```try{ $data = $this->request->getData(); }catch(Exception $ex){ }``` |
# |
Jul 26th 2021, 19:40 |
tyler.adam.lazenby |
those are entities |
# |
Jul 26th 2021, 19:40 |
tyler.adam.lazenby |
oh wait |
# |
Jul 26th 2021, 19:39 |
tyler.adam.lazenby |
can anybody tell me why this isn't iterating in the order that I am expecting (by first_name) ```$collection = new Collection($contact_list->contacts); $sorted = $collection->sortBy('first_name', SORT_ASC)->compile(); foreach ($sorted as $contact) {``` |