Passing array of models to view


I need to pass an array of models view a view for the purpose of updating a page which contains multiple images.

In my controller, I have

$criteria = new CDbCriteria();


$modelPageFile = PageFile::model()->findAll($criteria);

where f_id is the foreign key relating to the ID of the page.

At the moment I’m using



'modelPageFile' => $modelPageFile,


but the view (_form.php) is generating errors; here’s the mark up I’m using to create the file inputs

<div class="row">

<?php echo $form->labelEx($modelPageFile,'[0]Small image'); ?>

<?php echo $form->fileField($modelPageFile,'[0]Small image'); ?>

<?php echo $form->error($modelPageFile,'[0]Small image'); ?>

<?php echo $form->labelEx($modelPageFile,'[0]Large image'); ?>

<?php echo $form->fileField($modelPageFile,'[0]Large image'); ?>

<?php echo $form->error($modelPageFile,'[0]Large image'); ?>


error message is "get_class() expects parameter 1 to be object, array given".

How do I pass the array of models to my view for this purpose?

Many thanks


you should also pass these variables to the _form partial view to make them accessible in it:



	'modelPageFile' => $modelPageFile,


is $modelPageFile is NULL ?? check that first.


Many thanks for your comment - I’ll give it a try but I’m not sure if this will help since the update view is already calling renderPartial?

<?php echo $this->renderPartial('_form', array('model'=>$model,'modelPageFile' => $modelPageFile)); ?>

I’m trying with CActiveDataProvider at the moment.

Many thanks

Hi, I’m testing to see if it is - if so, am creating a new model

is this ‘[0]Small image’ a member of that model ?

no, its index for the $_FILES array so I can access eg $_FILES[0][‘Small Image’], $_FILES[1][‘Small Image’]. I’m doing it using CActiveDataProvider - the view is getting a bit messy, and I’m sure there’s better way to do it (show multiple images - small and large) for each (page) model you’re viewing.