We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how to define a model attribute <=> FORGET IT SOLVED

HI, I'm using a jquery plugin (the amazing vitalet's x-editable plugin) that allows you to inline edit your models. This plugin send via POST request parameters like:

pk=2 name=title value=my new title

where "name" is the attribute's name of my model that have to be updated .

Now in controller, I don't know how to deal with: $pk = $_POST['pk']; $name = $_POST['name']; $value = $_POST['value']; $media = Media::findFirst('id="'.$pk.'"'); $media->$name=$value; <--- how to set the attribute name to be updated

thanks for help

FORGET IT : SOLVED !!!

expression above is good, I've just forgotten to put $media->save() in my controller action !!!!



98.9k
Accepted
answer

hey li51, just a suggestion $media = Media::findFirst('id="'.$pk.'"'); is opening your application to a SQL injection, you could better use bound parameters:

$media = Media::findFirst(array('id = ?0', 'bind' => array($pk));
$media = Media::findFirstById($pk);


43.9k

thank you. Still have to learn some good practices :-)

Note: Media::findFirst('id="'.$pk.'"') is the code generated by devTools