aqua
(Niki Ianev)
August 16, 2013, 5:28pm
1
Hi,
I have the following problem:
I have a google map on one side, and a form which gets the info from the form on the other.
The form listens for map clicks to take actions.
Depending on the click it fills the form with data for an existing poi marker
or fills it with the coordinates of the empty space clicked and generates new marker on the map.
How can I tell Yii it is an existing record, while the form fill is happening entirely in front end?
Thanks,
Saylor
If you load your markers from database associate some extra information like the id with them. You surely keep them in some data structure in JS. If you can’t associate extra data with them, keep it somewhere and index it by by some information available in markers that can be used to uniqely identify them.
When you got the id matching the marker put it in the form in a hidden field or action attribute.
aqua
(Niki Ianev)
August 16, 2013, 8:35pm
3
nineinchnick:
If you load your markers from database associate some extra information like the id with them. You surely keep them in some data structure in JS. If you can’t associate extra data with them, keep it somewhere and index it by by some information available in markers that can be used to uniqely identify them.
When you got the id matching the marker put it in the form in a hidden field or action attribute.
Thank you, you got the point.
I already got all the fields necessary and displayed them in the form, the hidden ID field included.
the problem is I want to do insert and update through a single action method, and can’t imagine how to do it in Yii.
Can you tell me the best practice for this?
public function actionUpdate($id=null) {
if ($id===null) {
$model = new Model;
} else {
$model = Model::model()->findByPk($pk);
}
$model->setAttributes($_POST);
$model->save();
]
Of course, add some validation and error checking and everything else.