How to Recieve Array Data in a Custom Widget Class

In some view file dubai.php I’m calling the map widget and passing it some values


<?php $this->widget('Map', array('lat' => 25.126223, 'lon' => 55.208809, 'frameWidth' => 652, 'frameHeight' => 412)); ?>

The widget I have created has a view file location.php in the views folder of components folder. The Map widget class Map.php. Map class is to receive data and pass on to location.php file which does the work of displaying google map


<?php


class Map extends CWidget

{

  public function run()

  {

     $this->render('location', array('lat' => $lat, 'lon' => $lon, 'frameWidth' => $frameWidth, 'frameHeight' => $frameHeight));

  }

}

I get this error Property "Map.lat" is not defined.

Is the array data passed as $_GET variables ?


$this->render('location', array('lat' => What do I need to write here ?,

You need to define attributes to hold each value that you’re passing in.

You also need to ensure you’re referencing those attributes in the run() method, so you should prepend them with $this->




<?php


class Map extends CWidget

{

  public $lat;

  public $lon;

  public $frameWidth;

  public $frameHeight;


  public function run()

  {

     $this->render('location', array('lat' => $this->lat, 'lon' => $this->lon, 'frameWidth' => $this->frameWidth, 'frameHeight' => $this->frameHeight));

  }

}