unknownbits
unknownbits

Reputation: 2885

pass array to $this->beginWidget use in Header from controller?

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

Answers (1)

chris---
chris---

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.

for further reading

Upvotes: 1

Related Questions