Stuck on displaying "lazy relational query"

Ok. No problem. One more question… is there anyway to display ALL of the "firstname" as right now it will only display the first entry in the database.

In fact that should be possible already. If you use the example with CDetailView and the names array then you should see all the names separated with ', '. Maybe you only have one member assigned. Try another group

This is what I’m seeing:

Yet there are infact 2 entries I have added. I used the multiform extension (whole point of this "rigmarole"

put this in your view and tell me what it is saying:




foreach($model->members as $member)

{

    echo $member->firstname;

    echo '<br>';

}



If there is only one member than you don’t get more than that out of your DB

I got this, thanks!

Now how do I get that into the nice little table?

Did you use my code I posted some posts ago? And by that i mean exactly this code? Look at the array in CDetailView. The implode function and the $memberNames variable are essential




<?php $memberNames=array();

foreach($model->members as $member)

    $memberNames[]=$member->firstname;

?>

<?php $this->widget('zii.widgets.CDetailView', array(

        'data'=>$model,

        'attributes'=>array(

                'id',

                'title',

                array(

                    'label'=>'Members'

                    'type'=>'text',

                    'value'=>implode(', ',$memberNames)

                )

        ),

)); ?>



Yes I did:


<?php

$this->breadcrumbs=array(

	'Groups'=>array('index'),

	$model->title,

);


$this->menu=array(

	array('label'=>'List Group', 'url'=>array('index')),

	array('label'=>'Create Group', 'url'=>array('create')),

	array('label'=>'Update Group', 'url'=>array('update', 'id'=>$model->id)),

	array('label'=>'Delete Group', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),

	array('label'=>'Manage Group', 'url'=>array('admin')),

);

?>


<h1>View Group #<?php echo $model->id; ?></h1>


<?php 

$memberNames=array();

foreach($model->members as $member);

$memberNames[]=$member->firstname

	

?>

<?php foreach($model->members as $member)

{

	echo $member->firstname;

	echo '<br><center>';

}

?>


<?php $this->widget('zii.widgets.CDetailView', array(

    	'data'=>$model,

    	'attributes'=>array(

            	'id',

            	'title',

            	array(

                	'label'=>'First name',

                	'type'=>'text',

                	'value'=>implode(', ',$memberNames)

            	)

    	),

)); ?>

No, you didn’t ;)




foreach($model->members as $member);

$memberNames[]=$member->firstname



should be




foreach($model->members as $member)

$memberNames[]=$member->firstname;



ahahaha… thank you once again!!

One more question…

Is it possible to put the names in their own column instead of separated by comma? I have plans to make a very big list eventually.

I am sorry mate, but I can’t do everything for you. Just one hint: Use CDetailView to display the group attributes and below it you use CListView to display the related members. This is something you can do on your own with a little research :)

Ok thank you very much.You have helped me with the biggest pitfall and now I can finally move on for a bit more.