Yii Framework Forum: Stuck on displaying "lazy relational query" - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Stuck on displaying "lazy relational query" Rate Topic: -----

#21 User is offline   Queryton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-September 11

Posted 16 September 2011 - 11:10 AM

View PostHaensel, on 16 September 2011 - 11:09 AM, said:

No it is alright, I am happy we solved this issue. Just give me a +vote on one of my posts. That's enough ;)


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.
0

#22 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 16 September 2011 - 11:15 AM

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
0

#23 User is offline   Queryton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-September 11

Posted 16 September 2011 - 11:30 AM

This is what I'm seeing:

Posted Image



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

Posted Image


Posted Image

0

#24 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 16 September 2011 - 11:47 AM

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
0

#25 User is offline   Queryton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-September 11

Posted 16 September 2011 - 11:49 AM

View PostHaensel, on 16 September 2011 - 11:47 AM, said:

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!

Posted Image


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

#26 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 16 September 2011 - 11:53 AM

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)
                )
        ),
)); ?>

0

#27 User is offline   Queryton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-September 11

Posted 16 September 2011 - 11:56 AM

View PostHaensel, on 16 September 2011 - 11:53 AM, said:

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)
            	)
    	),
)); ?>

0

#28 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 16 September 2011 - 12:03 PM

No, you didn't ;)

foreach($model->members as $member);
$memberNames[]=$member->firstname


should be

foreach($model->members as $member)
$memberNames[]=$member->firstname;

1

#29 User is offline   Queryton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-September 11

Posted 16 September 2011 - 12:05 PM

View PostHaensel, on 16 September 2011 - 12:03 PM, said:

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!!
0

#30 User is offline   Queryton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-September 11

Posted 16 September 2011 - 12:08 PM

One more question.. Posted Image

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.
0

#31 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 16 September 2011 - 12:12 PM

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 :)
1

#32 User is offline   Queryton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 07-September 11

Posted 16 September 2011 - 12:13 PM

View PostHaensel, on 16 September 2011 - 12:12 PM, said:

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.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users