从api调用id时未定义的变量

时间:2017-12-18 09:46:30

标签: php function api url

我正在研究老师给我们的一个PHP项目,基本上我们必须创建一个动态的网站并创建一个liste.php,其任务存储在教师的API中。

所以我的index.php上有首页,所有项目的列表都在进行(如旅行准备,购物清单和公寓装饰)。我创建了一个liste.php,其中包含每个项目中包含的所有任务(购买门票,预订酒店并购买旅行准备的明信片)。

现在我必须从他给我们的API中获取每个项目的所有任务。

这是API

http://todo_api.xx.firstname-lastname.com/tache.php?liste_id=1

这是项目n°1的API,总共有3个项目(我在上面提到了它们)

我还有一个存有$ api_url的functions.php和2个函数,一个获取项目列表,另一个获取每个项目的任务。

$api_url = "http://todo_api.xx.firstname-lastname.com/";


function getAllListes(): array {
    global $api_url;

    $json = file_get_contents($api_url . "liste.php");
    return json_decode($json, true);
}



function getAllTaches(): array {
    global $api_url;
    $json = file_get_contents($api_url . "tache.php?liste_id=" . $id);
    return json_decode($json, true);
}

但是当我尝试print_r,甚至只显示每个任务时,我得到了这个:

注意:未定义的索引:第17行的/Applications/MAMP/htdocs/todo/database/functions.php中的liste_id

显然有些事情是错的,这使我无法继续下去。有什么想法吗?

编辑:这是关于任务列表的html / php代码

$listes = getAllListes();
$taches = getAllTaches($id);

<ul>

        <?php foreach ($taches as $tache) : ?>
        <li><?php echo $tache["libelle"] ;?></li>
        <?php endforeach ; ?>
    </ul>

libelle是所需信息的索引。

非常感谢!

1 个答案:

答案 0 :(得分:0)

您在functions.php中的代码

function getAllTaches(): array { //declared function without parameter

但是html / php代码

$taches = getAllTaches($id);// calling the function with parameter.

我想如果你将参数传递给函数它会起作用。

相关问题