Yii Framework Forum: Problem In Agile Web Application On Iteration 5 - Yii Framework Forum

Jump to content

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

Problem In Agile Web Application On Iteration 5

#1 User is offline   sldra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 11-October 12

Posted 01 March 2013 - 04:21 AM

hello.. I have the problem in yii web app regarding with the role dropdown list in iteration 5 in agile web applicattion tutorials..I followed the tutorials.bt I coudnt get the final result.it didnt view the role dropdown list...pls help mee.. thank you
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,734
  • Joined: 17-January 09
  • Location:Russia

Posted 01 March 2013 - 05:31 AM

Which tutorials are you talking about exactly?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   sldra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 11-October 12

Posted 05 March 2013 - 03:09 AM

Above mentioned problum arised on Agile Web Application Development with Yii 1.1 and PHP5 tutorial.
this is my adduser.php
<?php

$this->pageTitle=Yii::app()->name . ' - Add User To Project';
$this->breadcrumbs=array(
$model->project->name=>array('view','id'=>$model->project->id),'Add User');
$this->menu=array(
array('label'=>'Back To Project','url'=>array('view','id'=>$model->project->id)),
);
?>

<h1>Add User To <?php echo $model->project->name; ?></h1>

<?php if(Yii::app()->user->hasFlash('success')):?>

<div class="successMessage">
<?php echo Yii::app()->user->getFlash('success'); ?>
</div>

<?php endif; ?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm'); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>

<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php $this->widget('CAutoComplete', array(
'model'=>$model,
'attribute'=>'username',
'data'=>$usernames,
'multiple'=>false,
'htmlOptions'=>array('size'=>25),
)); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'role'); ?>
<?php echo $form->dropDownList($model,'role',Project::getUserRoleOptions()); ?>
<?php echo $form->error($model,'role'); ?>

</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Add User'); ?>
</div>
<?php $this->endWidget(); ?>
</div>


this is my 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 CalActiveRecord
{
/**
* 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'),
);
}

/**
* @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)'),
);
//create the Project model instance by primary key:
$model = Project::model()->findbyPk(1);
//get an array of all associated Issue AR instances
$allIssues = $model->issues;
//get an array of all associated User AR instance
$allUsers = $model->users;
//get the User AR instance representing the owner of
//the first issue associated with this project
$ownerOfFirstIssue = $model->issues[0]->owner;


}
/**
* @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()// by me
{
//$usersArray = array();
$usersArray = CHtml::listData($this->users, 'id', 'username');
return $usersArray;
}

/**
* creates an association between the project, the user and the
user's role within the project
*/
public function associateUserToRole($role, $userId)//by me
{
$sql = "INSERT INTO tbl_project_user_role (project_id, user_id,role) VALUES (:projectId, :userId, :role)";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId", $this->id, PDO::PARAM_INT);
$command->bindValue(":userId", $userId, PDO::PARAM_INT);
$command->bindValue(":role", $role, PDO::PARAM_STR);
return $command->execute();
}
/**
* removes an association between the project, the user and the
user's role within the project
*/
public function removeUserFromRole($role, $userId)// by me
{
$sql = "DELETE FROM tbl_project_user_role WHERE project_id=:projectId AND user_id=:userId AND role=:role";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId", $this->id, PDO::PARAM_INT);
$command->bindValue(":userId", $userId, PDO::PARAM_INT);
$command->bindValue(":role", $role, PDO::PARAM_STR);
return $command->execute();
}
/**
* @return boolean whether or not the current user is in the
specified role within the context of this project
*/
public function isUserInRole($role)// by me
{
$sql = "SELECT role FROM tbl_project_user_role WHERE project_id=:projectId AND user_id=:userId AND role=:role";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId", $this->id, PDO::PARAM_INT);
$command->bindValue(":userId", Yii::app()->user->getId(),
PDO::PARAM_INT);
$command->bindValue(":role", $role, PDO::PARAM_STR);
return $command->execute()==1 ? true : false;
}
/**
* Returns an array of available roles in which a user can be
placed when being added to a project
*/
public static function getUserRoleOptions()
{
return CHtml::listData(Yii::app()->authManager->getRoles(), 'name', 'name');
}
/**
* Makes an association between a user and a the project
*/
public function associateUserToProject($user)
{
$sql = "INSERT INTO tbl_project_user_assignment (project_id,user_id) VALUES (:projectId, :userId)";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId", $this->id, PDO::PARAM_INT);
$command->bindValue(":userId", $user->id, PDO::PARAM_INT);
return $command->execute();
}
/*
* Determines whether or not a user is already part of a project
*/
public function isUserInProject($user)
{
$sql = "SELECT user_id FROM tbl_project_user_assignment WHERE project_id=:projectId AND user_id=:userId";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId", $this->id, PDO::PARAM_INT);
$command->bindValue(":userId", $user->id, PDO::PARAM_INT);
return $command->execute()==1 ? true : false;
}



}
I cannot find the error.bt it doesnt view the role dropdownlist. pls help me. thank you
0

#4 User is offline   sldra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 11-October 12

Posted 05 March 2013 - 04:32 AM

Attached File  Capture.PNG (22.84K)
Number of downloads: 17 this is the result of above mentioned problem.dropdown list didnt work
0

#5 User is offline   sldra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 11-October 12

Posted 20 March 2013 - 11:15 AM

hey pls help me.still i can not find the sollution
0

#6 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 513
  • Joined: 08-August 09

Posted 21 March 2013 - 05:51 AM

Please check first of all if you have roles set up.

public static function getUserRoleOptions(){

var_dump(Yii::app()->authManager->getRoles());

exit;

return CHtml::listData(Yii::app()->authManager->getRoles(), 'name', 'name');

}


0

#7 User is offline   Joemaxwell 

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

Posted 18 April 2013 - 10:25 PM

View Postyugene, on 21 March 2013 - 05:51 AM, said:

Please check first of all if you have roles set up.

public static function getUserRoleOptions(){

var_dump(Yii::app()->authManager->getRoles());

exit;

return CHtml::listData(Yii::app()->authManager->getRoles(), 'name', 'name');

}




Hi I got this set-up on my on my Project.php i still don't see the drop down on roles (reader, member, owner) Any idea if i can manual insert this on mysql work bench. If it can to solve this drop down. I am trying to execute my Project Test.php and here is the result:


There was 1 failure:

1) ProjectTest::testGetUserRoleOptions
Failed asserting that 3 matches expected 0.

/Applications/MAMP/htdocs/trackstar/protected/tests/unit/ProjectTest.php:108.


line 108----------- $this->assertEquals(count($options),3);


0

#8 Guest_Ann D. Guerrero_*

  • Group: Guests

Posted 08 February 2014 - 06:47 AM

Which web application tutorials you are following ?
There are a great number of tutorials are available for yii web app in Agile,Scrum.
Check your tutorials again and tally your coding according the tutorials. I hope you get your mistake if you don't find your error send me a MP I will help 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