Yii Framework Forum: Many to Many relation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Many to Many relation Rate Topic: -----

#1 User is offline   Marina 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 23-April 11

Posted 06 May 2011 - 05:34 PM

if i have this relation between this tables

1-Employee(username,EmployeeID)

2-Status(StatusID,Name)

3-EmployeStatus(EmployeeId,StatusID)

how i can display status name in employee form and then save selected status id and employee id in EmployeeStatus Table

assume that each employee have many status so we save status id and employee id in EmployeeStatus

thanks alot please i need help in fast time
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 May 2011 - 06:06 PM

This question has been asked to death - so if you need answers in fast time: use the forum search.

It was asked as late as today IIRC..
"Less noise - more signal"
0

#3 User is offline   Marina 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 23-April 11

Posted 06 May 2011 - 06:36 PM

View Postjacmoe, on 06 May 2011 - 06:06 PM, said:

This question has been asked to death - so if you need answers in fast time: use the forum search.

It was asked as late as today IIRC..

please you can but some good links for this topic please i need fast help
0

#4 User is offline   adsmail27 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 30-April 11

Posted 06 May 2011 - 10:08 PM

First:
Create Relations in model
    public function relations()
    {
        return array(
            'status'=>array(self::MANY_MANY, 'Status', 'EmployeStatus(EmployeeId, StatusID)'),
        );
    }


Second:
Create Form in View
<div class="row">
            <?php echo $form->labelEx($model,'status'); ?>
            <?php echo $form->dropDownList($model, 'status',
                    CHtml::listData( Status::model()->findAll(), 'StatusID', 'Name'),
                    array(  'multiple'=>'multiple',
                            'size'=>5,
                    )); ?>
            <?php echo $form->error($model,'status'); ?>
        </div>


Finnaly
Create Function in controler
foreach ($_POST['Employee']['status'] as $statusId) {
            $statusJoin = new EmployeStatus;
            $statusJoin->EmployeeId = $model->id;
            $statusJoin->StatusID = $statusId;
        }



Yes We Can
0

Share this topic:


Page 1 of 1
  • 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