我知道解析错误,这样的事情是程序员 101,但我找不到文件有什么问题和错误“语法错误,文件意外结束”
遵循本教程帮助我了解了 php 和 Yii,但错误可能不在该文件中,可能是其他错误。很高兴你能帮我解决这个问题。
<?php
$this->pageTitle=Yii::app()->name . ' - Add User To Domain';
$this->breadcrumbs=array(
$model->domain->name=>array('view','id'=>$model->domain->id),
'Add User',
);
$this->menu=array(
array('label'=>'Back To Domain', 'url'=>array('view','id'=>$model->domain->id)),
);?>
<h1>Add User To <?php echo $model->domain->name; ?></h1>
<?php if(Yii::app()->user->hasFlash('success')):?>
<div class="successMessage">
<?php echo Yii::app()->user->getFlash('success'); ?>
</div>
<?phpendif; ?>
<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(); ?>
//错误发现谢谢tinyByte
另一个问题: Yii 告诉我这 'data'=>$usernames,
是一个未定义的变量:用户名
但在我的 UserForm 类 php 文件中,我有这个:
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;
}
我是否必须创建一个公共的 $usernames 或其他东西?