Log message #4268413

# At Username Text
# 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 https://book.cakephp.org/4/en/views/helpers/form.html#starting-a-form
# Jul 26th 2021, 20:26 cnizzardini For you then
# 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) {```
# Jul 26th 2021, 18:26 umer936 Yeah I'm reanalyzing how to handle it where I'm not pointing to a Controller not present, but need a quick fix as I rework things.