# |
Nov 30th 2017, 12:55 |
obinoob |
h.mavisakalian so what do you want to achieve now? you need to be pragmatic when naming variables... it's makes your code readable I'm not very good with that either but that is very important |
# |
Nov 30th 2017, 12:54 |
h.mavisakalian |
Sorry if this is frustrating for you all :slightly_smiling_face: |
# |
Nov 30th 2017, 12:53 |
johnwayne |
How can I group query by month and year -> https://pastebin.com/QWcUF3AT |
# |
Nov 30th 2017, 12:52 |
h.mavisakalian |
It works with get() when I fetch the data as you told me, get the ID from the array and then use get() with the ID |
# |
Nov 30th 2017, 12:51 |
h.mavisakalian |
Yes I did… |
# |
Nov 30th 2017, 12:51 |
h.mavisakalian |
$postUpdate = $postsTable->find()->where([ ‘postid’ => $post[‘id’] ]); $postUpdate->likes = $post[‘likes’][‘count’]; $postsTable->save($postUpdate); |
# |
Nov 30th 2017, 12:51 |
obinoob |
if you're lacking any of those you can't use an Entity to CRUD |
# |
Nov 30th 2017, 12:50 |
obinoob |
h.mavisakalian did you checked for Entity Class and Table Class as I told you to? |
# |
Nov 30th 2017, 12:49 |
h.mavisakalian |
“Argument 1 passed to Cake\ORM\Table::save() must implement interface Cake\Datasource\EntityInterface, instance of Cake\ORM\Query given” |
# |
Nov 30th 2017, 12:49 |
h.mavisakalian |
I did, but the save() function gives me an error when I save the entity |
# |
Nov 30th 2017, 12:49 |
obinoob |
h.mavisakalian in your case $this->Posts->find()->where(['id' => $id]); |
# |
Nov 30th 2017, 12:48 |
obinoob |
h.mavisakalian you can do $this->Posts->find(')->where(['district_id' => $district]); |
# |
Nov 30th 2017, 12:46 |
obinoob |
h.mavisakalian because it is implemented in a smarter way |
# |
Nov 30th 2017, 12:46 |
h.mavisakalian |
I just have the postId… which is custom from that JSON content |
# |
Nov 30th 2017, 12:46 |
h.mavisakalian |
well thats the whole point )))) I dont have the id of that record at that point |
# |
Nov 30th 2017, 12:45 |
h.mavisakalian |
also why doesn’t the ->get() method let you do something like ->get([‘postId’ => $post[‘id’]]) ? |
# |
Nov 30th 2017, 12:45 |
obinoob |
actually I missed a slash -> url: '/clients/add/'+$('input#id').val() |
# |
Nov 30th 2017, 12:44 |
obinoob |
if you're using ajax it's the same thing provide the id at -> url: '/clients/add'+$('input#id').val() |
# |
Nov 30th 2017, 12:44 |
h.mavisakalian |
Yes, I know that. I was just wondering if I can fetch that record using that PostID and get the id from my database |
# |
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 |