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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   yiinighter2000 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 08-January 17

Posted 12 June 2017 - 12:31 PM

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!!
0

#2 User is offline   Arockia Johnson SR 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 25-June 13
  • Location:Singapore

Posted 21 June 2017 - 04:02 AM

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!
மகிழ்ச்சியாக குறியிடுங்கள்!..... Happy Coding!.....


Thanks & Regards,
ஜான்சன் ( Arockia Johnson SR )
www.arojohnson.tk

Hit (+) button If my replies really helped you!
1

#3 User is offline   yiinighter2000 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 08-January 17

Posted 26 June 2017 - 03:02 AM

View Postஆரோக்கிய ஜான்சன், on 21 June 2017 - 04:02 AM, said:

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!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users