当我尝试调用 json 操作时遇到问题
首先,在yii _form.php中,我有一个包含输入名称的文本字段的表单,如下所示:
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form>textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>
</div>
我想要的是,当我输入字符“n”时,该字段实现(调用)我在独立 json 文件中定义的操作(例如 index.php?r=user/getuserdata),
read: {
url:"index.php?r=user/getuserdata",
dataType: "json",
type:"post"
},
在UserController.php中,有一个名为“actionGetUserData()”的函数,它告诉细节这个动作究竟做了什么。
public function actionGetUserData(){
$amount = User::model()->findAll("1 = 1 order by id DESC"); //為了排序
$count = count($amount);
for ($i=0;$i<$count;$i++){
$arr[$i]['id'] = $amount[$i]['id'];
$arr[$i]['username'] = $amount[$i]['username'];
$arr[$i]['userpwd'] = $amount[$i]['userpwd'];
$arr[$i]['usertype'] = $amount[$i]['usertype'];
$arr[$i]['modifytime'] = $amount[$i]['modifytime'];
$arr[$i]['createtime'] = $amount[$i]['createtime'];
$arr[$i]['allowip1'] = $amount[$i]['allowip1'];
$arr[$i]['allowip2'] = $amount[$i]['allowip2'];
$arr[$i]['allowip3'] = $amount[$i]['allowip3'];
$arr[$i]['allowip4'] = $amount[$i]['allowip4'];
$arr[$i]['allowip5'] = $amount[$i]['allowip5'];
/* $arr[$i][] = $amount[$i]->attributes; */
/* echo "<pre>";
print_r($amount[$i]->attributes);
echo "</pre>"; */
}
$result = json_encode($arr);
echo $result;
}
在这种情况下,让我们忽略函数究竟做了什么(只是一个例子)。我想知道,文本字段如何调用/触发 json 文件中的 getuserdata 操作index.php?r=user/getuserdata。这意味着如何在文本字段和 json 文件的操作之间建立关系。
请告诉我如何在 yii 中完成这项工作
_form.php(textfield) 触发json文件(动作)