这是我试图从url
调用它的函数 public function getParentId($childId)
{
$statment = $this->db->prepare("SELECT parent FROM `person` WHERE id = $childId");
$statment->execute();
$result = $statment->fetchAll();
foreach($result as $output){
return $output['parent'];
}
echo 'You call the function from url';
}
我编写了这段代码来访问url的函数
if(isset($_GET['action'])){
include_once('Family.php');
$object = new Family;
switch($_GET['action']){
case 'getId':
$object->getParentId($childId);
break;
default;
echo 'There is no function with that name';
break;
}
}
然后我从Url
传递参数test.local/Family.php?action=getId&childId=4
输出您可以从url
调用该函数但他没有返回$ output ['parent']为什么?
答案 0 :(得分:2)
我认为你打算编写第二段代码 像这样:
if(isset($_GET['action'])){
include_once('Family.php');
$object = new Family;
switch($_GET['action']){
case 'getId':
$object->getParentId($_GET['childId']); //<= Edit
break;
default;
echo 'There is no function with that name';
break;
}
}