简体   繁体   中英

In yii how to render view in widget

In yii i am creating project.

Now i want to create widget for displaying new password insertion window. For resetting password,user needs to enter security question's answer correctly. After this he will be provided with two radio buttons. One is having label as "Change password here" and other as "Send password reset link to mail".

So when user will clicks first radio button,this widget will get rendered which will have two textfields for entering new password and repeat password, and also submit button. So how to implement this widget.

I had created simple widget saying hello as:

class Sample extends CWidget {
  public function init() {
    Yii::app()->getClientScript()->registerScript('SampleWidget',"alert('Hello');");
  }
}

So how to add textfields and submit button to this widget. Or how to render any view form in this widget. Please help me.

use $this->render() method which will render a partial view (no layout) from your widgets/views folder.

$this->render('my-widget',array());

check here

Rendering a widget is the same as rendering any other view. Just set layout property to a different value so you don't get the header again. public $layout='//layouts/noheader'; You can set that property in your method like $this->layout = '//layouts/noheader'. This will also let you do custom things for example I have a layout that is for popups. You should also create it as a partial so it can be used in other places.

Do not forget this construction:

return $this->render('$viewname');

I forget to write return and spend much time for searching the error;
hopes it help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM