如何在php中为前端设置后端数组

时间:2017-04-27 18:04:19

标签: php arrays

**我希望将后端数据设置为前端作为arry。怎么做。在backend.php文件下面有另一个html标签。请任何人都可以帮助我。 **

backend.php

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>

frontend.php

if (isset($_POST['submit'])) { 
    extract($_POST);        
    $autofill = $supervisor->check_auto_fill($studentUniversityId);

}

1 个答案:

答案 0 :(得分:0)

使用$ this-&gt; set('array',$ arr);在控制器中。

或者在视图中直接调用函数By:使函数静态然后 使用 : 应用::使用( “MODELNAME”, “模式”); $ ARR = MODELNAME :: CalledFunction($属性);