如何在php中为前端设置后端数组
**我需要将后端数据设置到前端作为arry。如何做到这一点。在backend.php文件下面有另一个html标记。任何人都可以帮助我** backend.php如何在php中为前端设置后端数组,php,arrays,Php,Arrays,**我需要将后端数据设置到前端作为arry。如何做到这一点。在backend.php文件下面有另一个html标记。任何人都可以帮助我** backend.php public function check_auto_fill($studentUniversityId){ $query = "SELECT supervisor.lecturerName, supervisee.studentName, supervisee.studentUniversityId FROM sup
public function check_auto_fill($studentUniversityId){
$query = "SELECT supervisor.lecturerName, supervisee.studentName, supervisee.studentUniversityId FROM supervisee, supervisor WHERE supervisee.lecturerId = supervisor.lecturerId AND supervisee.studentUniversityId = '$studentUniversityId' ";
$result = $this->db->query($query) or die($this->db->error);
$supervisor_data = $result->fetch_array(MYSQLI_ASSOC);
$arr = array(
'lecturerName' => $supervisor_data[0]['lecturerName'],
'studentName' => $supervisor_data[0]['studentName'],
);
return $arr;
}
<form action="" method="post">
<label for="studentID">Student ID</label>
<input type="text" name="studentUniversityId" id="studentID" placeholder="studentID">
<!--input type="submit" id="autoFill" name="autoFill" value="Auto Fill"><br><br>
<input class="btn" type="submit" name="submit" value="Auto Fill"-->
<label for="studentName">Student Name</label>
<input type="text" id="studentName" name="studentName" value = "" placeholder="Student Name"><br><br>
<label for="lecturerName">Supervisor Name</label>
<input type="text" id="lecturerName" name="lecturerName" value = "<?php echo $autofill['lecturerName'];?>" placeholder="Supervisor Name"><br><br>
<?php print_r ($arr);?>
<input type="submit" id="submit" name="submit" value="submit">
</form>
if (isset($_POST['submit'])) {
extract($_POST);
$autofill = $supervisor->check_auto_fill($studentUniversityId);
}
使用$this->set('array',$arr);在控制器中
或者直接调用函数(如果在视图中):使函数为静态,然后
使用:
应用程序::使用(“模型名”、“模型”);
$arr=ModelName::CalledFunction($attributes) -您应该知道MVC结构,因此:如果您从控制器中的模型调用此函数,您将通过$this->set()发送数据;在控制器中-如果您想直接从模型调用它:App::uses(“ModelName”、“model”)$arr=ModelName::CalledFunction($attributes);这里显示的内容似乎与CakePHP无关,请确保使用了正确的标记。也就是说,您在那里构建的是一个SQL注入漏洞,永远不要将(用户)数据直接插入查询,始终使用准备好的语句@ndm,如果你是真正的天才,给我答案。