所以我開始使用MVC。我不使用框架。這只是自我實踐。PHP檢查所有輸入是否設置不起作用?
所以這是我的註冊部分:
protected function _instance()
{
if ($_POST != null)
{
/**
* Validating if forms are not empty
**/
if (self::validateForms())
{
echo 1;
}
else
{
new Error("One of the forums was empty..");
}
}
}
private static function validateForms()
{
$inputs = array (
'username', 'password', 'repassword',
'email', 'password_f', 'repassword_f',
'display'
);
$i = 0;
foreach ($inputs as $key)
{
if (isset($_POST[$key]) && !empty($_POST[$key]))
{
$i++;
if ((int) $i == count($inputs))
{
return true;
}
else
{
return false;
}
}
}
}
現在,只需檢查輸入設定如果沒有,拋出錯誤。 但它似乎不起作用,因爲它總是運行該錯誤。
$i
每次輸入已滿時必須增長,但我不認爲它確實如此。
當我回顯$i
時,它只回顯「1」。
爲什麼它只循環一次?
我怎麼會錯過!一定很累。非常感謝! –