Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:07:26+00:00 2026-06-08T19:07:26+00:00

I use yii framework to create map application.In this application i use GeoExt and

  • 0

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',
                'success'=>"function(){
                        alert('ok');
                    }"
            ));
        ?>
        $("#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

   class SiteController extends Controller
   {
public $polygon;
public function actionTest()
    {
       if(isset($_POST['polygon']))
            $this->polygon=$_POST['polygon'];

         $this->render("test", array('polygon'=>$this->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!
In the above code i can see success alert but i can’t see site controller polygon in test view and $polygon is Null!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:07:28+00:00Added an answer on June 8, 2026 at 7:07 pm

    I believe that your code is probably working – adding a var_dump($_POST) in actionTest() would be a good place to start.

    Since you’re making an AJAX call, the $this->render() is not returning to the browser the way you’re expecting. I would imagine that in the Chrome Developer Tools, Network tab, then then Response tab, you’ll see ‘data’.

    In general, to get data back, you’d want something like:

    public function actionTest()
    {
       if(isset($_POST['polygon']))
            $polygon = $_POST['polygon'];
        else
            $polygon = NULL;
        echo CJSON::encode(array('polygon'=>$polygon));
    }
    

    To access the returned data, you could use a callback in your AJAX, e.g. :

         <?php 
            echo CHtml::ajax(array(
                'url'=>array('site/test'),
                'data'=>array('polygon'=>'data'),
                'type'=>'POST',
                'dataType': 'json',
                'success' : "function(data) { console.log(data.polygon) }",
            ));
        ?>
    

    This would log the value of polygon to the console . . . modify the success function to output this somewhere more useful.

    Your current method sounds as if it’s failing since you’re accessing site/test directly in your browser via the address bar, which means that $_POST won’t have anything in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use yii::app()->user->id in a form and to save the username in
I'm trying to create small application on Yii framework but can't understand one moment.
I'm building a web application and eventually would want to use Yii framework. But
I'm use Yii PHP framework but i cant write this code, what's the true
With Yii php framework, I use inheritance. In my AbstractModel, I have this method:
in Yii framework, can I use unique validation rule to check uniqueness of an
I use subversion to manage my yii website (php framework) and have separate backend
In Yii framework I used migration just like ./yiic migrate create tbl_demo it made
I wish to use a PHP Framework such as Yii, however, it seems to
I'm use Yii Framework. I have a named anchor <a name=projet>projet</a> in about.php page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.