Yii Framework Forum: Chapter 8 Adding User To Test Project - Yii Framework Forum

Jump to content

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

Chapter 8 Adding User To Test Project

#1 User is offline   Loginet 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-March 14

Posted 10 March 2014 - 03:13 PM

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.

Attached File(s)


0

#2 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 08-October 12
  • Location:Austria

Posted 19 May 2014 - 02:39 AM

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>

Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
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