Chapter 8 Adding User To Test Project

I´m having an issue adding users to projects, i´m getting an error:

include(exists.php): failed to open stream: No such file or directory.

Here´s my code:

ProjectController:


public function actionAdduser($id)

	{

		$form = new ProjectUserForm;

		$project = $this->loadModel($id);

		//collect user input data

		if (isset($_POST['ProjectUserForm'])) 

		{

			$form->attributes = $_POST['ProjectUserForm'];

			$form->project = $project;


			//Validate user input and set a sucessfull flash message if valid

			if ($form->validate()) 

			{

				Yii::app()->user->setFlash('success', $form->username." has been added to the project");

				$form = new ProjectUserForm;

			}

		}


		//display the add user form 

		$users = User::model()->findAll();

		$usernames = array();

		foreach ($users as $user) {

			$usernames[] = $user->username;

		}

		$form->project = $project;

		$this->render('addUser', array('model'=>$form, 'usernames'=>$usernames));

	}

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>

I´d appreciate your help, I really don´t know what the problem is.

Hi,problem is in your code :)

Your code





<div class="row">

<?php echo $form->labelEx($model,'usernames'); ?> // here not usernames it is username

<?php $this->widget('CAutoComplete', array(

'model'=>$model,

'attribute'=>'usernames',// here not usernames it is username

'data'=>$usernames,

'multiple'=>false,

'htmlOptions'=>array('size'=>25),

)); ?>

<?php echo $form->error($model,'username'); ?>

</div>



This is the original code





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