名前が一致する場合にコントローラーをロードする URL があると想像してください (現時点では、これに関するセキュリティ上の問題は無視しています)
public function Load( $controller, $action = "Index" )
{
require_once( "Controllers/" . $controller . "Controller.php" );
$controllerName = $controller . "Controller";
$loadedController = new $controllerName();
$actionName = "ActionResult_" . $action;
$loadedController->$actionName();
}
ここで、上記で起動した受信側コントローラーのパラメーターとして $_POST の詳細を送信するログイン フォームが必要であるとします。
<?php
class ExcelUploadController extends Controller
{
public function ActionResult_Login( $username = NULL, $password = NULL )
{
// The parameters need to be mapped to the $_POST parameters names probably from the Load method somewhere and pumped in to the $loadedController->$actionName();
$post_username = $username;
$post_password = $password;
$this->ReturnView( "ExcelUpload/Index" );
}
}
?>
ただし、パラメーターが宣言されている順序が問題にならないように、 $_POST キーに基づいて関数内のパラメーターと一致します。
どうすればこれを行うことができますか、何かアイデアはありますか?
これが意味をなさないかどうかを明確にするために..メソッドは次のようになります。
public function Load( $controller, $action = "Index" )
{
require_once( "Controllers/" . $controller . "Controller.php" );
$controllerName = $controller . "Controller";
$loadedController = new $controllerName();
$actionName = "ActionResult_" . $action;
$checkIfPostData = $_POST;
if( isset( $checkIfPostData ) )
{
// Do some funky wang to map the following $loadedController->$actionName();
// with the username and password or any other $_POST keys so that in the calling method, I can grab hold of the $_POST values
}
$loadedController->$actionName();
}