Problem In Agile Web Application On Iteration 5

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

Which tutorials are you talking about exactly?

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">

&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'username'); ?&gt;


&lt;?php &#036;this-&gt;widget('CAutoComplete', array(


'model'=&gt;&#036;model,


'attribute'=&gt;'username',


'data'=&gt;&#036;usernames,


'multiple'=&gt;false,


'htmlOptions'=&gt;array('size'=&gt;25),


)); ?&gt;


&lt;?php echo &#036;form-&gt;error(&#036;model,'username'); ?&gt;


&lt;/div&gt;


&lt;div class=&quot;row&quot;&gt;


&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'role'); ?&gt;


&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'role',Project::getUserRoleOptions()); ?&gt;


&lt;?php echo &#036;form-&gt;error(&#036;model,'role'); ?&gt;





&lt;/div&gt;


&lt;div class=&quot;row buttons&quot;&gt;


&lt;?php echo CHtml::submitButton('Add User'); ?&gt;


&lt;/div&gt;


&lt;?php &#036;this-&gt;endWidget(); ?&gt;


&lt;/div&gt;

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 &#036;className active record class name.


 * @return Project the static model class


 */


public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;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'=&gt;true),


		array('name', 'length', 'max'=&gt;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'=&gt;'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' =&gt; array(self::HAS_MANY, 'Issue', 'project_id'),


		'users' =&gt; array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)'),


			);	


		//create the Project model instance by primary key:


		&#036;model = Project::model()-&gt;findbyPk(1);


		//get an array of all associated Issue AR instances


		&#036;allIssues = &#036;model-&gt;issues;


		//get an array of all associated User AR instance


		&#036;allUsers = &#036;model-&gt;users;


		//get the User AR instance representing the owner of


		//the first issue associated with this project


		&#036;ownerOfFirstIssue = &#036;model-&gt;issues[0]-&gt;owner;


			


		


		}


/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'id' =&gt; 'ID',


		'name' =&gt; 'Name',


		'description' =&gt; 'Description',


		'create_time' =&gt; 'Create Time',


		'create_user_id' =&gt; 'Create User',


		'update_time' =&gt; 'Update Time',


		'update_user_id' =&gt; '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.





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('id',&#036;this-&gt;id);


	&#036;criteria-&gt;compare('name',&#036;this-&gt;name,true);


	&#036;criteria-&gt;compare('description',&#036;this-&gt;description,true);


	&#036;criteria-&gt;compare('create_time',&#036;this-&gt;create_time,true);


	&#036;criteria-&gt;compare('create_user_id',&#036;this-&gt;create_user_id);


	&#036;criteria-&gt;compare('update_time',&#036;this-&gt;update_time,true);


	&#036;criteria-&gt;compare('update_user_id',&#036;this-&gt;update_user_id);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}


			/**


		* @return array of valid users for this project, indexed by user IDs


		*/


		public function getUserOptions()// by me


		{


		//&#036;usersArray = array();


		&#036;usersArray = CHtml::listData(&#036;this-&gt;users, 'id', 'username');


		return &#036;usersArray;


		}


		


		/**


		* creates an association between the project, the user and the


		user's role within the project


		*/


		public function associateUserToRole(&#036;role, &#036;userId)//by me


		{


		&#036;sql = &quot;INSERT INTO tbl_project_user_role (project_id, user_id,role) VALUES (:projectId, :userId, :role)&quot;;


		&#036;command = Yii::app()-&gt;db-&gt;createCommand(&#036;sql);


		&#036;command-&gt;bindValue(&quot;:projectId&quot;, &#036;this-&gt;id, PDO::PARAM_INT);


		&#036;command-&gt;bindValue(&quot;:userId&quot;, &#036;userId, PDO::PARAM_INT);


		&#036;command-&gt;bindValue(&quot;:role&quot;, &#036;role, PDO::PARAM_STR);


		return &#036;command-&gt;execute();


		}


		/**


		* removes an association between the project, the user and the


		user's role within the project


		*/


		public function removeUserFromRole(&#036;role, &#036;userId)// by me


		{


		&#036;sql = &quot;DELETE FROM tbl_project_user_role WHERE project_id=:projectId AND user_id=:userId AND role=:role&quot;;


		&#036;command = Yii::app()-&gt;db-&gt;createCommand(&#036;sql);


		&#036;command-&gt;bindValue(&quot;:projectId&quot;, &#036;this-&gt;id, PDO::PARAM_INT);


		&#036;command-&gt;bindValue(&quot;:userId&quot;, &#036;userId, PDO::PARAM_INT);


		&#036;command-&gt;bindValue(&quot;:role&quot;, &#036;role, PDO::PARAM_STR);


		return &#036;command-&gt;execute();


		}


					/**


		* @return boolean whether or not the current user is in the


		specified role within the context of this project


		*/


		public function isUserInRole(&#036;role)// by me


		{


		&#036;sql = &quot;SELECT role FROM tbl_project_user_role WHERE project_id=:projectId AND user_id=:userId AND role=:role&quot;;


		&#036;command = Yii::app()-&gt;db-&gt;createCommand(&#036;sql);


		&#036;command-&gt;bindValue(&quot;:projectId&quot;, &#036;this-&gt;id, PDO::PARAM_INT);


		&#036;command-&gt;bindValue(&quot;:userId&quot;, Yii::app()-&gt;user-&gt;getId(),


		PDO::PARAM_INT);


		&#036;command-&gt;bindValue(&quot;:role&quot;, &#036;role, PDO::PARAM_STR);


		return &#036;command-&gt;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()-&gt;authManager-&gt;getRoles(), 'name', 'name');


		}


		/**


		* Makes an association between a user and a the project


		*/


		public function associateUserToProject(&#036;user)


		{


		&#036;sql = &quot;INSERT INTO tbl_project_user_assignment (project_id,user_id) VALUES (:projectId, :userId)&quot;;


		&#036;command = Yii::app()-&gt;db-&gt;createCommand(&#036;sql);


		&#036;command-&gt;bindValue(&quot;:projectId&quot;, &#036;this-&gt;id, PDO::PARAM_INT);


		&#036;command-&gt;bindValue(&quot;:userId&quot;, &#036;user-&gt;id, PDO::PARAM_INT);


		return &#036;command-&gt;execute();


			}


			/*


			* Determines whether or not a user is already part of a project


			*/


			public function isUserInProject(&#036;user)


			{


			&#036;sql = &quot;SELECT user_id FROM tbl_project_user_assignment WHERE project_id=:projectId AND user_id=:userId&quot;;


			&#036;command = Yii::app()-&gt;db-&gt;createCommand(&#036;sql);


			&#036;command-&gt;bindValue(&quot;:projectId&quot;, &#036;this-&gt;id, PDO::PARAM_INT);


			&#036;command-&gt;bindValue(&quot;:userId&quot;, &#036;user-&gt;id, PDO::PARAM_INT);


			return &#036;command-&gt;execute()==1 ? true : false;


			}

}

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

3894

Capture.PNG
this is the result of above mentioned problem.dropdown list didnt work

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

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