1

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?

1
  • Did you get solution of it? Commented May 13, 2014 at 18:32

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

What do you mean with "header"? Is this a view part in your layout view?
That's a bit tricky. See here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.