CodeIgniterでHMVCパターンを使用しています。modules :: run()関数を介して2つのモジュールをロードするコントローラーがあり、パラメーターが各モジュールに渡されます。
どちらかのモジュールが渡されたパラメーターと一致しない場合は、show_404()を呼び出します。動作しますが、既存のテンプレート内にエラーページの完全なHTMLが読み込まれるため、HTMLが壊れて、ひどく見えます。エラーページにリダイレクトして、2番目のモジュールを実行しないようにしたいと思います。URLを変更せずにそれを行う方法はありますか?
URLを変更せずにモジュールからshow_404()にリダイレクトすることは可能ですか?
これは、何が起こっているのかを単純化した例です。
www.example.com/users/profile/usernamehere
URLは、ユーザーコントローラーで次の関数を呼び出します。
function profile($username)
{
echo modules::run('user/details', $username);
echo modules::run('user/friends', $username);
}
これらのモジュールを実行し、ユーザーが存在するかどうかを確認します。
function details($username)
{
$details = lookup_user($username);
if($details == 'User Not Found')
show_404(); // This seems to display within the template when what I want is for it to redirect
else
$this->load->view('details', $details);
}
function friends($username)
{
$details = lookup_user($username);
if($friends == 'User Not Found')
show_404(); // Redundant, I know, just added for this example
else
$this->load->view('friends', $friends);
}
私はそれを達成するためのより良い方法があると思いますが、私はそれを見ていません。何か案は?