24/01/2013 2:45am

PHP | Working Example - extrafield handler


	function extrafields(SS_HTTPRequest $req) {

$params = array_merge($req->params(),$req->postVars());
$model = $params['ModelClass'];
$relations = $model::$belongs_many_many;
//only support one many many
if(empty($relations)) {
exit();
}
$externalModel = current($relations);
$externalRels = $externalModel::$many_many;
if(empty($externalRels)) {
exit();
}
$relationName = key($externalRels);
$table = $externalModel . '_' . $relationName;
$field = $params['field'];
$value = Convert::raw2sql($params['value']);
$id = (int) $params['id'];
DB::query("UPDATE $table SET $field = '$value' WHERE ID = $id");
echo 'Record updated';die();
}


Post Comment