Search code examples
yiirenderpartial

Yii renderPartial only some form fields


I need to include a view (_form) that shows only certain fields.

$user = new User;
$this->renderPartial('//User/_form', array('model'=>$user));

In this function, you can specify which fields to show?

Thanks


Solution

  • you can show what folder it is, like for example in views/user/_form :

    $this->renderPartial('application.views.user._form', array('model'=>$user));
    

    http://www.yiiframework.com/doc/api/1.1/CController#renderPartial-detail

    UPDATE: you can send renderPartial a variable and check for that variable with your logic, in _form.php

    in form.php

    $this->renderPartial('application.views.user._form',
         array('model'=>$user , 'condition'=>$condition));
    

    in your _form.php

    if($conition == 'check for something') // show the field, or Not!
    {
        echo $form->textField($user, 'username');
    }