Reputation: 2885
I am using Widget in my Header layout.
In My controller .I have set following variables:
public $testVal="testing";
I have created a widget in YII and I use it in my Header layout:
<?php $this->beginWidget('CountryWithCityWidget'); $this->endWidget();?>
My widget Code is:
<?php
class CountryWithCityWidget extends CWidget
{
public $countryList;
public $cityList;
public function init()
{
print_r($testVal);// I need $testVal testing here from view ***How ????***
echo "==============================";
die;
parent::init();
}
public function run()
{
$this->render('countryWithCityWidget',array('countryList' => $this->countryList,'locationDetailList'=>$this->cityList));
}
}
?>
In view I will get it like $this->testVal
and then from view I want to send $testVal to widget where I am using it.
How can I do that?
Upvotes: 1
Views: 193
Reputation: 1546
Try
$this->widget('CountryWithCityWidget', array(
'testVal' => $testVal
));
and add a property testVal
to your widget class. Also pass your $testVal
var to your view.
Upvotes: 1