0
我有一個函數,使代碼的回波的功能裏面,這樣我就不必每次重複:絕對URL包括與甲基苯丙胺
function echo_snippets($connection, $query, $snippet, $variable_1, $variable_2, $variable_3, $variable_4, $variable_5, $variable_5){
$result = $connection->query("CALL $query");
if($result){
while ($row = $result->fetch_object()){
include 'includes/snippets/'.$snippet.'';
}
$result->close();
$connection->next_result();
}
}
然後我調用函數從網頁:
<?php
echo_snippets($connection,'index_php_Query_one()', 'echo_things.php', '', '', '', '', '', ''); ?>
// Empty spaces are for variables I can use sometimes.
?>
然後在/includes/snippets/echo_things.php包含的文件我也有變量和回聲:
<?php
$first_thing = $row-> first_thing;
$second_thing = $row-> second_thing;
echo '<div>This is the first_thing: '.$first_thing.'
and the second_thing:'.$second_thing.'</div>';
?>
一切正常。但是我在函數內部的包含url的問題上存在問題。我無法使用相對url,因爲我無法從目錄內調用該函數。我在MAMP本地目錄中工作,以及由於某種原因,它不接受絕對地址:
include 'http://localhost:8888/includes/snippets/'.$snippet.'';
我發現的唯一的解決辦法是通過絕對URL調用函數時
echo_snippets($connection,'index_php_Query_one()', '../includes/snippets/echo_things.php', '', '', '', '', '', ''); ?>
但我想知道有一種方法可以爲函數提供絕對url。
A.
爲什麼你不能使用GETCWD()來得到當前的工作目錄? – VK321