Detect $models array before use it!

hi, I checked errata page, don’t find this, so I write here,

in Page 96 3. there are some code like this:




<ul class="tasks">

		<?php if(is_array($models) && count($models)):?>

			<?php for($i=0; $i < count($models); $i++):?>

				<?php $this->renderPartial('_task', array(

                                                                          'model'=>$models[$i],

                                                                           'index'=>$i,

                                                                            )

                                                            );

				?>

			<?php endfor?>

		<?php endif?>

	</ul>



but because in 2. there are also assing $models as object, code like this:




if(!empty($models)) {

			//could be saved to DB here

		} else {

			$models = new Task();

		}



if w/o checking of $models in index.php, then people will get error, because there is not model in $models[0]

so maybe man can append code like this:




<?php if(is_array($models) && count($models)):?>

    <?php for($i=0; $i < count($models); $i++):?>

              ....

    <?php endfor?>

<?php endif?>



Or there is other solution? Please help, thank you!

forget it, I was wrong, I make $models[] = new Task() as $model = new Task();

in book all correct. Sorry.