Question

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

Was it helpful?

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');
}

OTHER TIPS

renderPartial only renders the provided view file (without including layout), so if you want to include only some of the form fields you will have to pass some variable (like an array) which will output the parts of a code using if statement (or similar idea).

In short the answer to your question will be: NO. renderPartial works like render the difference is that it renders the view file without including layout file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top