2017-09-05 35 views
0

是否可以在HTML的某個部分的引導警報中顯示源自PHP的錯誤?它們是我想在主頁面上顯示的example.php文件中的警報。我試着PHP創建功能是我想提醒去,像這樣......PHP - 在頁面頂部發布提醒

主文件功能

所包含

... 
postAlert(true,'This is an error example'); 
... 

function postAlert($good, $text) { 
    $type = 'danger'; 
    if($good){ 
     $type = 'success'; 
    } 
    echo '<div class="alert alert-'.$type.' alert-dismissable"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong> '. $text.' </strong></div>'; 
    } 

示例文件嘗試在其中一個示例php文件中調用此函數,但似乎沒有任何事情發生,也沒有發生錯誤。有什麼我做錯了嗎?還是有更好的方法來做到這一點?

<?php include 'navbar.php'; ?> 

<!-- Alert goes here --> 

<div class="container"> 
    <div class="row"> 
    <?php include 'example1.php' ?> 
    <?php include 'example2.php' ?> 
    <?php include 'example3.php' ?> 
    </div> 
</div> 

回答

1

在PHP .用於concatenation.While您使用的警報+。改變你的功能如下

function postAlert($good, $text) { 
    $type = 'danger'; 
    if($good){ 
     $type = 'success'; 
    } 
    echo '<div class="alert alert-'.$type.' alert-dismissable"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong> ' . $text . ' </strong></div>'; 
    } 
+0

我固定它,但仍然沒有什麼區別 – SillySam

+0

在該文件已被稱爲'postAlert'功能? –

+0

我在example2.php腳本中調用了它 – SillySam