可能であれば、助けをお願いします。
リダイレクト後に$_GETが設定されたときにいくつかのメッセージを表示するために、2つの関数を作成しました。コードは次のとおりです。
function display(){
if(isset($_GET['cnf_upd']) && $_GET['cnf_upd'] == '1'){
$value = "The update was successful!";
$type = "confirm";
construct_the_div($value, $type);
}
if(isset($_GET['err_upd']) && $_GET['err_upd'] == '1'){
$value = "The Update failed.";
$type = "error";
construct_the_div($value, $type);
}
if(isset($_GET['cnf_del']) && $_GET['cnf_del'] == '1'){
$value = "Deleted completely.";
$type = "confirm";
construct_the_div($value, $type);
}
if(isset($_GET['err_del']) && $_GET['err_del'] == '1'){
$value = "Unable to delete.";
$type = "error";
construct_the_div($value, $type);
}
}
function construct_the_div($value, $type){
// creating a div to display the message results
$div = "<div class=\"{$type}Msg\">\n";
$div .= "<p>{$value}</p>\n";
$div .= "</div><!-- end of {$type}Msg -->\n";
echo $div;
}
私が作りたいのは、表示機能がどんどん長くなるので、可能であればifステートメントが1つ(または多くても2つ)になるように、表示機能を改善することです。したがって、GETの値は動的にif条件内にあり、プレフィックス'cnf_'がある場合は'confirmMsg'になり、プレフィックス'err_'がある場合は'errorMsg'になります。
このようなものを作ることは可能ですか?