Yii Framework Forum: Problems With Projectuserform View - Yii Framework Forum

Jump to content

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

Problems With Projectuserform View Error: Property "CJuiAutoComplete.soruce" is not defined.

#1 User is offline   Yerok 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-April 14

Posted 14 May 2014 - 03:20 PM

Hello,

I have a problem with the ProjectUserForm view. I get the following error:

Property "CJuiAutoComplete.soruce" is not defined. I googled the error but found nothing what helped me to solve my problem.

I copyed the view file, like it is printed in the book:

<?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('zii.widgets.jui.CJuiAutoComplete', 
						  array(
							'name' => 'username',
							'soruce' => $model->createUsernameList(),
							'model' => $model,
							'attribute' => 'username',
							'options' => array('minLength' => '2',),
							'htmlOptions' => array('style' => 'height: 20px;'),
						)
					);
		?>  
		<?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('AddUser'); ?>
	</div>

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


This is the addUserAction in my projectController:

	public function actionAdduser($id)
	{
		$project = $this->loadModel($id);
		/*
		if(!Yii::app()->user->checkAccess('createUser', array('project' => $project)))
		{
			throw new CHttpException(403, 'You are not authorizes to perform this action');
		}
		*/
		$form = new ProjectUserForm;
		
		//collect user input data
		
		if(isset($_POST['ProjectUserForm']))
		{
			$form->attributes = $_POST['ProjectUserForm'];
			
			$form->project = project;
			
			if($form->validate())
			{
				if($form->assign())
				{
					Yii::app()->user->setFlash('sucess', $form->username . " has been added to the project.");
					//reset the form for another user to be associated if desired
					$form->unsetAttributes();
					$form->clearErrors();
				}
			}
		}
		
		$form->project = $project;
		$this->render('adduser', array('model' => $form));
	}


This is the project user form:

<?php
/**
* ProjectUserForm class.
* ProjectUserForm is the data structure for keeping
* the form data related to adding an existing user to a project. It is used by the 'Ad-duser' action of 'ProjectController'.
*/
class ProjectUserForm extends CFormModel
{
/**
* @var string username of the user being added to the project
*/
public $username;
/**
* @var string the role to which the user will be associated within the project
*/
public $role;
/**
* @var object an instance of the Project AR model class
*/
public $project;
private $_user;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated using the verify() method
*/
public function rules()
{
	return array(
		// username and role are required
		array('username, role', 'required'),
		//username needs to be checked for existence
		array('username', 'exist', 'className'=>'User'),
		array('username', 'verify'),
	);
}
 
/**
* Authenticates the existence of the user in the system.
* If valid, it will also make the association between the user, role and project
* This is the 'verify' validator as declared in rules().
*/
public function verify($attribute,$params)
{
	if(!$this->hasErrors()) // we only want to authenticate when no other input errors are present
	{
		
		$user = User::model()->findByAttributes(array('username'=>$this->username));
		if($this->project->isUserInProject($user))
		{
			$this->addError('username','This user has already been added to the project.');
		}
		else
		{
			$this->_user = $user;
		}
	}
}
public function assign()
{
	if($this->_user instanceof User)
	{
		//assign the user, in the specified role, to the project
		$this->project->assignUser($this->_user->id, $this->role);
		//add the association, along with the RBAC biz rule, to our RBAC hierarchy
		$auth = Yii::app()->authManager;
		$bizRule='return isset($params["project"]) && $params["project"]->allowCurrentUser("'.$this->role.'");';
		$auth->assign($this->role,$this->_user->id, $bizRule);
		return true;
	}
	else
	{
		$this->addError('username','Error when attempting to assign this user to the project.');
		return false;
	}
}
	/**
	* Generates an array of usernames to use for the autocomplete
	*/
	public function createUsernameList()
	{
		$sql = "SELECT username FROM tbl_user";
		$command = Yii::app()->db->createCommand($sql);
		$rows = $command->queryAll();
		//format it for use with auto complete widget
		$usernames = array();
		
		foreach($rows as $row)
		{
			$usernames[]=$row['username'];
		}
		
		return $usernames;
	}
	
}


I don't know whats going wrong here. I would be pleasured if someone can give me a advice.

Thank You
0

#2 User is offline   chandran 

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

Posted 15 May 2014 - 03:04 AM

Hi,

simple you have to rename soruce to source :)
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