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.


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.


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

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

check here


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

链接地址: http://www.djcxy.com/p/69726.html

上一篇: yii引导程序+小部件TbButtonColumn +小部件TbButtonGroup

下一篇: 在yii中如何在小部件中呈现视图