# |
Dec 20th 2017, 21:09 |
spencdev |
Can't use Security and Csrf at the same time |
# |
Dec 20th 2017, 21:08 |
greenjam94 |
File uploaded https://cakesf.slack.com/files/U8H4R4KNV/F8JNBTJEB/-.php / https://slack-files.com/T053DPNCM-F8JNBTJEB-c56cedea1f - <@U43JSV0SK> |
# |
Dec 20th 2017, 21:06 |
greenjam94 |
can I create a snippet here instead of gist? |
# |
Dec 20th 2017, 21:05 |
spencdev |
where you load `$this->loadComponent('Csrf');` |
# |
Dec 20th 2017, 21:04 |
spencdev |
your controllers `initialize` function |
# |
Dec 20th 2017, 21:04 |
greenjam94 |
Sorry, my initialize? |
# |
Dec 20th 2017, 21:03 |
spencdev |
Can you gist your initialize @greenjam94 |
# |
Dec 20th 2017, 20:40 |
greenjam94 |
Hi, I need to submit a form over ajax, I have a X-CSRF-TOKEN as explained in https://book.cakephp.org/3.0/en/controllers/components/csrf.html#csrf-protection-and-ajax-requests but it errors because _Token is missing from the form. Any suggestions? |
# |
Dec 20th 2017, 20:09 |
night_wulfe |
I'm not sure, sorry. I haven't used patchEntities before. |
# |
Dec 20th 2017, 19:58 |
kailas |
@night_wulfe i’m trying to just do a save with associated entities. in my form I have a set of fields that have hte fields for each of the associated entities to update. however, when I do patchEntity, it doesn’t merge the new values, but just overwrites the values in the associated entities. does that make sense? why would that be occuring? I thought it would just merge in changes but leave the unchanged fields as they are |
# |
Dec 20th 2017, 19:38 |
night_wulfe |
@kailas |
# |
Dec 20th 2017, 19:38 |
night_wulfe |
https://book.cakephp.org/3.0/en/orm/query-builder.html#updating-data |
# |
Dec 20th 2017, 19:38 |
night_wulfe |
I'd use the Query Builder and execute the SQL directly. |
# |
Dec 20th 2017, 17:50 |
kailas |
or if i iterate through associated entities, and then save once, will the save be a bulk update? |
# |
Dec 20th 2017, 17:48 |
kailas |
Is there a way to update many records at one? similar to a update (foo left join bar on foo.id=bar.foo_id) set foo.a=‘asdf’ where bar.blah=something (my syntax may be a bit off, but hta’t sthe concept). rather than iterating through my results and updating/saving one at a time? |
# |
Dec 20th 2017, 16:23 |
spencdev |
Then after the post, `patchEntity($varNameOfEntity, $this->request->data())` |
# |
Dec 20th 2017, 16:17 |
spencdev |
That's typically how it is. Because when you post, you are technically reloading the page. So you should create your entity once, before the `request->is(['post'])` I know that's is 3.x, I can't really remember what the 2.x was |
# |
Dec 20th 2017, 16:16 |
devito |
i think what is happening is I am declaring my entity 2x. once on page load and then again on post |
# |
Dec 20th 2017, 16:14 |
spencdev |
and also, make sure your form is pointed to the same action that you are using to show the form. In other words, unless you specifically need it to go to another action, leave the `url` option blank. |
# |
Dec 20th 2017, 16:13 |
spencdev |
^ I literally almost had that exact thing typed |
# |
Dec 20th 2017, 16:12 |
hmic |
devito: 1. don't redirect on error, 2. make sure you set the actual patched, failed saving, entity to the form at creation time! (or an empty entity on first load without submitting data) |
# |
Dec 20th 2017, 16:11 |
devito |
hmm ok. let me take another look. |
# |
Dec 20th 2017, 16:09 |
dereuromark |
it should not redirect, but stay on the page, including all errors on the form inputs. and only after success you can redirect away |
# |
Dec 20th 2017, 16:08 |
dereuromark |
reloads? then you messed up the form building. |
# |
Dec 20th 2017, 16:07 |
devito |
Noticed something odd, after a form submission fails because of Model rules the page doesnt seem to accept the next form post. it reloads the page and the user has to start again. Is there a way to refresh a page after a failed save and cary over the entity errors? |
# |
Dec 20th 2017, 14:56 |
admad |
All with* methods return a new instance |
# |
Dec 20th 2017, 14:55 |
admad |
@jotpe your example code did not work because you did not assign the return value of withStringBody() to a var. |
# |
Dec 20th 2017, 14:28 |
vignesh.pattalam |
yes just realised, I thought you were linking to a plugin initially that did it |
# |
Dec 20th 2017, 14:27 |
admad |
it's 3 lines of code to get the list of tables from db |
# |
Dec 20th 2017, 14:26 |
vignesh.pattalam |
oh ok, I'll take a closer look then thank you :slightly_smiling_face: |
# |
Dec 20th 2017, 14:26 |
admad |
instead of having to do the typing |
# |
Dec 20th 2017, 14:26 |
admad |
those are core methods, i just showed you how to use them |
# |
Dec 20th 2017, 14:25 |
vignesh.pattalam |
@admad Thank you for that link! So does this mean there is no method in Core CakePHP to find if a table exists in the database ? Is there any plans to bring it to the core or is crud-view going to be the solution for this ? |
# |
Dec 20th 2017, 14:25 |
jotpe |
The file isn't existing, should be created from data on the fly |
# |
Dec 20th 2017, 14:25 |
k4t |
Here you can also see how I am calling that XYZ action from cURL: https://gist.github.com/K4T/13b01c3d2c572394a390174e6db5697d |
# |
Dec 20th 2017, 14:24 |
admad |
https://api.cakephp.org/3.5/class-Cake.Http.Response.html#_withFile |
# |
Dec 20th 2017, 14:23 |
jotpe |
@admad, not sure, but withStringBody does not output the content of the file: https://pastebin.com/5uds03gm |
# |
Dec 20th 2017, 14:20 |
k4t |
the problem is only when I am calling that XYZ action from cURL from another PHP script |
# |
Dec 20th 2017, 14:19 |
k4t |
I can also manually call XYZ action directly from the browser - everything is ok in that situation |
# |
Dec 20th 2017, 14:18 |
k4t |
I also checked received cookies from cURL request in XYZ action and I can see that session cookie was sent, but still user session is not visible |
# |
Dec 20th 2017, 14:17 |
slackebot3 |
request which are taken from $_SERVER['HTTP_COOKIE']). I can not find why it is not working. Did I miss something? |