# |
Nov 30th 2017, 12:43 |
obinoob |
h.mavisakalian you have read my small example right? so in order to supply the param id you need to put in in the url like this: http://domain/controller/action/param |
# |
Nov 30th 2017, 12:43 |
h.mavisakalian |
so I can use get() to fetch that record and update it… with just a few lines |
# |
Nov 30th 2017, 12:41 |
h.mavisakalian |
and update it with a entity |
# |
Nov 30th 2017, 12:41 |
h.mavisakalian |
if there is I just want to get the ID of that post in my database |
# |
Nov 30th 2017, 12:41 |
h.mavisakalian |
I am checking if there is a record that has that “PostID” ( which I get from the external source ) |
# |
Nov 30th 2017, 12:41 |
obinoob |
You will need both check under src/Model/Entity for Post.php and in src/Model/Table for PostsTable.php and pay attention to naming convention cakes uses it a lot |
# |
Nov 30th 2017, 12:40 |
h.mavisakalian |
using ->newEntity(); ( you were correct ) |
# |
Nov 30th 2017, 12:40 |
h.mavisakalian |
Look… when I am adding the data to the database |
# |
Nov 30th 2017, 12:39 |
h.mavisakalian |
One question though |
# |
Nov 30th 2017, 12:39 |
obinoob |
h.mavisakalian now in order to use an entity you need to have a Entity class and a Table class for Posts |
# |
Nov 30th 2017, 12:39 |
h.mavisakalian |
@obinoob Thanks |
# |
Nov 30th 2017, 12:36 |
obinoob |
h.mavisakalian this is the very basics off course |
# |
Nov 30th 2017, 12:35 |
obinoob |
h.mavisakalian so you want to update a registry, you need to pass an id to your action method... even if you are using ajax it's the same thing! Assuming you are using an entity the method should go like this: https://gist.github.com/obinoob/c97ce7f598997e8440b1efe0e87ba462 |
# |
Nov 30th 2017, 12:27 |
obinoob |
h.mavisakalian use https://gist.github.com/ or other |
# |
Nov 30th 2017, 12:27 |
h.mavisakalian |
This is what I want to do and it doesn’t work |
# |
Nov 30th 2017, 12:26 |
h.mavisakalian |
if ($exists) { $postUpdate = $postsTable->find()->where([ ‘postid’ => $post[‘id’] ]); $postUpdate->comments = $post[‘comments’][‘count’]; $postsTable->save($postUpdate); } |
# |
Nov 30th 2017, 12:26 |
obinoob |
h.mavisakalian what do you want to do in plain english |
# |
Nov 30th 2017, 12:26 |
obinoob |
h.mavisakalian I'm confused, don't use code and explain your aim |
# |
Nov 30th 2017, 12:25 |
h.mavisakalian |
now I need to do this |
# |
Nov 30th 2017, 12:24 |
h.mavisakalian |
like this |
# |
Nov 30th 2017, 12:24 |
h.mavisakalian |
$exists = $postsTable->exists([‘postId’ => $post[‘id’]]); |
# |
Nov 30th 2017, 12:23 |
h.mavisakalian |
I only have the postId with which I can check if a record exists in the database with that postId |
# |
Nov 30th 2017, 12:23 |
h.mavisakalian |
which I dont have at that moment as I am adding a new post to the database form external source |
# |
Nov 30th 2017, 12:22 |
h.mavisakalian |
and get(); needs an ID for it to work |
# |
Nov 30th 2017, 12:20 |
Leonardo_0112 |
Hi! A little help with cakephp3 validation: https://pastebin.com/0gP3NnVB |
# |
Nov 30th 2017, 12:19 |
ksandeep_ |
no, |
# |
Nov 30th 2017, 12:19 |
h.mavisakalian |
“Argument 1 passed to Cake\ORM\Table::save() must implement interface ” |
# |
Nov 30th 2017, 12:19 |
h.mavisakalian |
error comes up |
# |
Nov 30th 2017, 12:19 |
h.mavisakalian |
it doesn’t let me save |
# |
Nov 30th 2017, 12:19 |
h.mavisakalian |
if I retrieve a record using find()->where() |
# |
Nov 30th 2017, 12:18 |
obinoob |
ksandeep_: have you seen anything suspicious? |
# |
Nov 30th 2017, 12:18 |
h.mavisakalian |
the update only works with ->get(); |
# |
Nov 30th 2017, 12:18 |
spriz |
it sounds like some funky things you’re trying to do |
# |
Nov 30th 2017, 12:17 |
spriz |
and/or read the link from obinoob and then https://book.cakephp.org/3.0/en/orm/saving-data.html#updating-data |
# |
Nov 30th 2017, 12:17 |
obinoob |
h.mavisakalian "gist" your code |
# |
Nov 30th 2017, 12:17 |
spriz |
then your problem is somewhere else. It sounds like you should try the cake tutorial on book.cakephp.org |
# |
Nov 30th 2017, 12:17 |
h.mavisakalian |
and checks if the custom POST ID exists in the database |
# |
Nov 30th 2017, 12:17 |
obinoob |
h.mavisakalian git your code |
# |
Nov 30th 2017, 12:17 |
h.mavisakalian |
this function works when I add data from JSON url |
# |
Nov 30th 2017, 12:16 |
h.mavisakalian |
there is no ID i can use |
# |
Nov 30th 2017, 12:16 |
obinoob |
h.mavisakalian you didn't asked that: [11:42] <slackebot2> <h.mavisakalian> How do you get the ID of an existing record ? |