我试图从model
中提取数据,其结果是数组。我试图将返回对象传递给我的controller
,并在JSON
中回显结果,但似乎无法接收该对象。
我制作的另一个php
文件不是MC
模式。它的工作原理。
这是我获取objects
的代码(这个有效 - 顺序方法):
if($_SERVER['REQUEST_METHOD'] == 'GET'){
require('dbConnect.php');
$SQLi_ORG_FEEDS = "SELECT organizationName,
organizationDescription,
organizationCategory,
organizationCurrentMembers,
organizationMaxMembersNo,
organizationType,
organizationLogo,
organizationLogoPath
FROM org_information";
$query = mysqli_query($dbConnect,$SQLi_ORG_FEEDS) or die("Error".mysqli_error($dbConnect));
$checkRow = mysqli_num_rows($query);
$response = array();
if($checkRow > 0){
while ($getRecord = mysqli_fetch_array($query)) {
$response[] = $getRecord;
}
echo json_encode($response);
}
else {
$response['failed'] = 'failed';
echo json_encode($response);
}
结果POSTMAN
此方法来自我的model
:
public function getAllOrgRegistered(){
//STATEMENT
$sql_show_org = "SELECT organizationName,
organizationDescription,
organizationCategory,
organizationCurrentMembers,
organizationMaxMembersNo,
organizationType,
organizationLogo,
organizationLogoPath
FROM org_information";
//EXECUTE
$result = mysqli_query($this->db->connect,$sql_show_org) or die(mysqli_error($this->db->connect));
$checkResults = mysqli_num_rows($result);
$response = array();
//CHECK FOR RESULTS
if ($checkResults > 0) {
while ($getRecord = mysqli_fetch_array($result)) {
$response[] = $getRecord;
}
return $response;
}else{
return FALSE;
}
}
我回应json
对象。 如何从model
到我的controller
收到此回复?
if($_SERVER['REQUEST_METHOD'] == 'GET'){
//INCLUDE CLASS
require_once($_SERVER['DOCUMENT_ROOT'] .'/yayongeppn/OOP/models/orgCreateOrganization.php');
//NEW INSTANCE OF AN OBJECT
$orgCreate = new orgCreateOrganization();
//TAG
$tag = $_POST['tag'];
if($tag == 'org'){
$response = array();
$result = $orgCreate->getAllOrgRegistered();
if ($result != FALSE) {
// while ($getRecord = mysqli_fetch_array($result)) {
// $response[] = $getRecord;
// }
echo json_encode($result);
}else{
$response['error'] = "Failed to fetch data.";
echo json_encode($response);
}
}
}//END SERVER
我真的需要你的帮助。