OOP PHP에서 MVC 프레임 워크를 사용할 때 양식을 제출할 때 페이지를 새로 고쳐야 다음 "elseif"로 이동해야합니다.OOP에서 폼을 제출 한 후 새로 고침하지 않아도 됨 PHP
"$ login-> isConfigFileCreated()"함수가 이제 (클래스 생성자가 실행 된 후에) true를 반환하더라도 이전과 동일한 뷰를 보여 주며 "move on"을 새로 고침해야합니다.
"createConfigFile() 함수"에 문제가 없다는 것을 확실히 알고 있습니다. 이것은 나에게 공통적 인 문제입니다.
이public function __construct()
{
if (isset($_POST["create_config_file"]))
{
$this->createConfigFile();
}
if (isset($_POST["register"]))
{
$this->register();
}
}
public function isAdminCreated()
{
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!$this->db_connection->connect_errno)
{
$checksetup = $this->db_connection->query("SELECT user_email FROM users WHERE user_id = '1';");
if ($checksetup->num_rows == 1)
{
return true;
}
else
{
return false;
}
}
}
public function isConfigFileCreated()
{
if(defined('DB_HOST') && defined('DB_NAME') && defined('DB_USER') && defined('DB_PASS'))
{
return true;
}
else
{
return false;
}
}
public function createConfigFile($action)
{
if ($action == "complete")
{
$file_content = file_get_contents("db.php");
$file_content .= 'define("CONFIG_DONE", "true");';
file_put_contents("db.php", $file_content);
}
else
{
$this->db_connection = new mysqli($_POST['input_db_host'], $_POST['input_db_user'], $_POST['input_db_pass'], $_POST['input_db_name']);
if (!$this->db_connection->connect_errno)
{
$file_content = '<?php'."\n";
$file_content .= 'define("DB_HOST", "'.$_POST['input_db_host'].'");'."\n";
$file_content .= 'define("DB_NAME", "'.$_POST['input_db_name'].'");'."\n";
$file_content .= 'define("DB_USER", "'.$_POST['input_db_user'].'");'."\n";
$file_content .= 'define("DB_PASS", "'.$_POST['input_db_pass'].'");'."\n";
file_put_contents("db.php", $file_content);
fclose("db.php");
$login->messages[] = "That's it! You're now ready to kick ass at some image management!";
}
else
{
$this->errors[] = "Wrong database credentials!";
}
}
}
시나리오를 확장 할 수 있습니까? 질문하십시오. '당신은 다음 페이지로 넘어가려면 페이지를 새로 고쳐야 만합니다.'elseif '그리고 코드와 관련이 있습니까? – Gordon
네 질문 중 어느 쪽인지 정확히 모르겠다 – Kris
isConfigFileCreated() 함수가 false를 반환하면 코드는 config_file.php를 보여줍니다. 그런 다음 양식을 작성하고 제출 버튼을 누릅니다. 페이지가 다시로드되고 생성자가 실행되고 제출을 누른 것을보고 설정 파일을 만듭니다.이 모든 것은 "$ login = new Login();"줄에서 발생합니다. 생성자가 $ _POST를 확인하기 때문에. 그러나 이것 이후에 ir는 표시 할 내용을 확인하고 config_file.php AGAIN을 표시합니다. 파일이 생성 되었더라도. 하지만 한 번 새로 고침하면 계속 움직입니다. – MathiasJakobsen