Yii Framework Forum: Can't Get Owner And Requester Username Dropdown - Yii Framework Forum

Jump to content

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

Can't Get Owner And Requester Username Dropdown Can't get owner and requester username dropdown

#1 User is offline   agus kianto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-January 13

Posted 20 January 2013 - 03:10 PM

I am on chapter six in the book and I got some difficulties in showing drop down list of username.

I put get_project function in issue controller:

public function getProject()
{
return $this->_project;
}

I put getUserOptions in project model:
public function getUserOptions()
{
$usersArray = CHtml::listData($models, 'id', 'username');
return $usersArray;
}

I set relations as:
In project model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),
'users' => array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),
);
}

In Issue model:

public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'requester' => array(self::BELONGS_TO, 'User', 'requester_id'),
'owner' => array(self::BELONGS_TO, 'User', 'owner_id'),
'project' => array(self::BELONGS_TO, 'Project', 'project_id'),
);
}

And I get a blank page for owner drop down list. (see picture for clearer problem.)

Attached File(s)


0

#2 User is offline   agus kianto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-January 13

Posted 20 January 2013 - 03:30 PM

public function getUserOptions()
{
$usersArray = CHtml::listData($this->users, 'id', 'username');
return $usersArray;
}

sorry forget to update the bold part.

And... here is the view of create new issue:
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'name',
'description',
array(
'name'=>'type_id',
'value'=>CHtml::encode($model->getTypeText()),
),
array(
'name'=>'status_id',
'value'=>CHtml::encode($model->getStatusText()),
),
array(
'name'=>'owner_id',
'value'=>CHtml::encode($model->owner->username),
),
array(
'name'=>'requester_id',
'value'=>CHtml::encode($model->requester->username),
)
),
));
?>
0

#3 User is offline   alienwerks 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-October 12

Posted 01 February 2013 - 11:58 PM

View Postagus kianto, on 20 January 2013 - 03:30 PM, said:

public function getUserOptions()
{
$usersArray = CHtml::listData($this->users, 'id', 'username');
return $usersArray;
}

sorry forget to update the bold part.

And... here is the view of create new issue:
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'name',
'description',
array(
'name'=>'type_id',
'value'=>CHtml::encode($model->getTypeText()),
),
array(
'name'=>'status_id',
'value'=>CHtml::encode($model->getStatusText()),
),
array(
'name'=>'owner_id',
'value'=>CHtml::encode($model->owner->username),
),
array(
'name'=>'requester_id',
'value'=>CHtml::encode($model->requester->username),
)
),
));
?>


Hi, did you resolve the problem?if not try to change your getUserOptions into
public function getUserOptions(){
$usersArray = CHtml::listData($this->tblUsers, 'id', 'username');//instead of users
return $usersArray;
}

Hope this helps
0

#4 User is offline   Joemaxwell 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 13-February 13
  • Location:Fiji Via Melbourne

Posted 03 April 2013 - 05:44 PM

I got the same issue no drop down on Owner_Id and requester_id.

Project.php
<?php

/**
* This is the model class for table "tbl_project".
*
* The followings are the available columns in table 'tbl_project':
* @property integer $id
* @property string $name
* @property string $description
* @property string $create_time
* @property integer $create_user_id
* @property string $update_time
* @property integer $update_user_id
*/
class Project extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Project the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}

/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tbl_project';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('create_user_id, update_user_id', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>128),
array('description, create_time, update_time', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, name, description, create_time, create_user_id, update_time, update_user_id', 'safe', 'on'=>'search'),
array('name, description', 'required'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),
'users' => array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Name',
'description' => 'Description',
'create_time' => 'Create Time',
'create_user_id' => 'Create User',
'update_time' => 'Update Time',
'update_user_id' => 'Update User',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
$criteria->compare('description',$this->description,true);
$criteria->compare('create_time',$this->create_time,true);
$criteria->compare('create_user_id',$this->create_user_id);
$criteria->compare('update_time',$this->update_time,true);
$criteria->compare('update_user_id',$this->update_user_id);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* @return array of valid users for this project, indexed by user IDs
*/
public function getUserOptions()
{
$usersArray = CHtml::listData($this->users, 'id', 'username');
return $usersArray;
}
}



My Issue/view.php

<?php
/* @var $this IssueController */
/* @var $model Issue */

$this->breadcrumbs=array(
'Issues'=>array('index'),
$model->name,
);

$this->menu=array(
array('label'=>'List Issue', 'url'=>array('index')),
array('label'=>'Create Issue', 'url'=>array('create')),
array('label'=>'Update Issue', 'url'=>array('update', 'id'=>$model->id)),
array('label'=>'Delete Issue', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
array('label'=>'Manage Issue', 'url'=>array('admin')),
);
?>

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

<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'name',
'description',
'type_id',
'status_id'
array(
'name'=>'owner_id',
'value'=>CHtml::encode($model->owner->username),
),
array(
'name'=>'requester_id',
'value'=>CHtml::encode($model->requester->username),
)
),
)); ?>


My Issue/_form.php

<?php
/* @var $this IssueController */
/* @var $model Issue */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'issue-form',
'enableAjaxValidation'=>false,
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>256)); ?>
<?php echo $form->error($model,'name'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'description'); ?>
<?php echo $form->textField($model,'description',array('size'=>60,'maxlength'=>2000)); ?>
<?php echo $form->error($model,'description'); ?>
</div>

<div class="row">
<?php echo $form->hiddenField($model,'project_id'); ?>
<?php echo $form->hiddenField($model,'project_id'); ?>
<?php echo $form->error($model,'project_id'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'type_id'); ?>
<?php echo $form->dropDownList($model,'type_id', $model->getTypeOptions()); ?>
<?php echo $form->error($model,'type_id'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'status_id'); ?>
<?php echo $form->dropDownList($model,'status_id', $model->getStatusOptions()); ?>
<?php echo $form->error($model,'status_id'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'owner_id'); ?>
<?php echo $form->dropDownList($model,'owner_id', $this->getProject()->getUserOptions()); ?>
<?php echo $form->error($model,'owner_id'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'requester_id'); ?>
<?php echo $form->dropDownList($model,'requester_id', $this->getProject()->getUserOptions()); ?>
<?php echo $form->error($model,'requester_id'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'create_time'); ?>
<?php echo $form->textField($model,'create_time'); ?>
<?php echo $form->error($model,'create_time'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'create_user_id'); ?>
<?php echo $form->textField($model,'create_user_id'); ?>
<?php echo $form->error($model,'create_user_id'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'update_time'); ?>
<?php echo $form->textField($model,'update_time'); ?>
<?php echo $form->error($model,'update_time'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'update_user_id'); ?>
<?php echo $form->textField($model,'update_user_id'); ?>
<?php echo $form->error($model,'update_user_id'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

Thank you.
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