想象我有一個加載的控制器的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();
}
我使用的方法是將關聯數組作爲單個參數並添加保障條件來匹配按鍵。 –
在接收方法中,你的意思是?任何例子的傢伙? – Jimmyt1988
@JamesT你應該將用戶輸入抽象爲某種類型的Request類實例,然後將其作爲單個參數傳遞給方法:public function postLogin(Request $ request){..'你可能會發現[this] (http://stackoverflow.com/a/13396866/727208)發佈* [無恥自我推銷] *有些有用。 –