Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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


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


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);


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

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