注:出力バッファリングを使用しています。これは、head()関数とfoot()関数にラップされているだけです。
次のテンプレートを使用して、現在のPHPプロジェクトにページを作成します。
<?php
include 'bootstrap.php';
head();
?>
<!-- Page content here -->
<?php
foot();
?>
次の例はdie()の適切な使用法ですか?また、これが私にどのような問題を引き起こす可能性がありますか?
<?php
include 'bootstrap.php';
head();
try
{
//Simulate throwing an exception from some class
throw new Exception('Something went wrong!');
}
catch(Exception $e)
{
?>
<p>Please fix the following error:</p>
<p><?php echo $e->getMessage(); ?></p>
<?php
foot();
die();
}
//If no exception is thrown above, continue script
doSomething();
doSomeOtherThing();
foot();
?>
基本的に、複数のタスクを含むスクリプトがあり、スクリプトの残りの部分が実行されないようにしながら、入力エラーをユーザーに通知する適切な方法を設定しようとしています。
ありがとう!