yii 1.1x: i get 404 when i try to pass a variable from view to widget

In my yii app, i get a date string via ajax get then i try to pass it to my feature widget. The thing is that sometimes i get the date via GET url and sometimes i use a default one that i get directly in the widget (so in that case no variable needs to be passed). Here is the code:

controller:


    public function actionGetDate($date) {		

        $this->render('index',array('date' =>$date));

    }

The $date passes to the view without any problem.

My view:


    if (isset($date))

    {

    	echo "$date !!!!";

    	$this->widget('FullWidget',array('date2' =>$date) );

    } else {

    	echo "not date";

    	$this->widget('FullWidget');

    }

when $date is not set, then the code runs without any issue.

when $date is set and then it goes to this line below and it gets me 404 Error…

$this->widget('FullWidget',array('date2' =>$date) );

here is 404 error:

"Error 404"

nothing more then that.

FullWidget:


<?php




    class FullWidget extends CWidget {

    

        private $_userConfig;

    

        public function init() {

    

            $this->_userConfig = Yii::app()->getModule('module1234')->getDefaultConfig();     

    	}

    

        public function run() {

        if (isset($date2))

    {

    	echo "yes!!!";

    	//$this->render('small_Widget', array('config' => $this->_userConfig,'date' => $date2));// this line is commented and i dont run it yet. the problem is when i'm trying to pass the variable from the view to the FullWidget 	

        }else{

    		echo "no!!!!";

    		$this->render('small_Widget', array('config' => $this->_userConfig));

    	}

    

    }

    }



Does anybody knows whats the problem?

Thanks!!

Hi,

At your widget you don’t have any public property called “date” then how it will run?





class FullWidget extends CWidget {


    private $_userConfig;

    public $date; //This is the point you are missing


    public function init() {

        $this->_userConfig = Yii::app()->getModule('module1234')->getDefaultConfig();

    }


    public function run() {

        if (isset($this->date)) {

            echo "yes!!!";

            $this->render('small_Widget', array('config' => $this->_userConfig, 'date' => $this->date));

        } else {

            echo "no!!!!";

            $this->render('small_Widget', array('config' => $this->_userConfig));

        }

    }


}

From your widget




$this->widget('FullWidget',array('date' =>$date) ); // not date2 .. use the name which is a property mentioned from the widget class



I hope it has helped you!

thanks!! you really helped me!