I use yii framework to create map application.In this application i use GeoExt and Openlayers.In this App user can draw polygon and save this for achieving this after user draw polygon and click on it(OpenLayers feature) i send polygon with ajax to save that on database but i can’t get any ajax data from controller action in yii framework.See below code!
var selectOptions = {
clickout: true,
onSelect: save
};
select = new OpenLayers.Control.SelectFeature(vectors, selectOptions);
map.addControl(select);
var saveButton = new Ext.Button({
text: 'Save',
enableToggle: true,
toggleGroup: toggleGroup,
handler: function(toggled)
{
if(toggled){
polygon.deactivate();
modify.deactivate();
select.activate();
}
}
function save(feature) {
var geojson_format = new OpenLayers.Format.GeoJSON();
var str = geojson_format.write(feature, true);
Ext.MessageBox.prompt('Name', 'Please enter district name:', "Ok");
<?php
echo CHtml::ajax(array(
'url'=>array('site/test'),
'data'=>array('polygon'=>'data'),
'type'=>'POST'
));
?>
$("#output").val(str);
}
in the save function i use yii Chtml::ajax to send polygon to Yii site controller test action in this php code i send polygon with ‘data’ for testing but in real i want to send str variable that is polygon geojson object to controller action.At the end of function i use $("#output").val(str); for testing geojson str var i see the output in the output textarea but i don’t know why data doesn’t send to controller action! controller action Code
public function actionTest()
{
if(isset($_POST['polygon']))
$polygon = $_POST['polygon'];
else
$polygon = NULL;
$this->render("test", array('polygon'=>$polygon));
}
for testing functionality i create a polygon in the map and click save button after this button is toggled i click on the created polygon i see polygon geojson object in the output textarea but when i want to see polygon object in the browser with http://localhost/FleetManagement/index.php/site/test i see only Null!! test view code:
<?php
var_dump($polygon);
?>
Below is save function in the chrome developer tools!
function save(feature) {
var geojson_format = new OpenLayers.Format.GeoJSON();
var str = geojson_format.write(feature, true);
Ext.MessageBox.prompt('Name', 'Please enter district name:', "Ok");
jQuery.ajax({'url':'/FleetManagement/index.php/site/test','data':{'polygon':'data'},'type':'POST','cache':false}); $("#output").val(str);
}
when i debug i see JQuery.ajax line execute but i don’t know this line can send data or no! because when i see test view i only see Null!