PHP와 HTML을 혼합하는 데있어서 조직에 큰 문제가 있다는 것을 알았습니다. 단지 끔찍한 것 같아요. 그래서 객체 지향적 인 방법을 만드는 것이 가능한지 궁금합니다.PHP와 HTML을 혼합 할 때 깨끗한 코드 통합
다음class MainOO {
public $Database;
public function __construct($Server,$User, $Password, $DB){
if ($this->Database = new mysqli($Server,$User,$Password,$DB)){
return true;
}
return false;
}
public function User_Login(){
$Get_Usr_Info = $this->Database->prepare("SELECT ID, Password, Salt FROM Users WHERE Username=?");
$Get_Usr_Info->bind_param('s',$_POST['username']);
$Get_Usr_Info->execute();
$Get_Usr_Info->store_result();
$User_Number = $Get_Usr_Info->num_rows;
$Get_Usr_Info->bind_result($UserID, $Stored_Password, $Stored_Salt);
$Get_Usr_Info->fetch();
$Get_Usr_Info->close();
if ($User_Number !== 1){
$Error = "Wrong Username Specified Or Password Is Incorrect";
header ("Location: index.php?Errors=".urlencode($Error));
exit;
}
// Continue with login script
}
public function Logout(){
if (session_status() !== PHP_SESSION_DISABLED){
session_destroy();
header ("Location: LoggedOut.php");
exit;
}
}
}
HTML 측 :이 같은
<?php
include "MainOO.php";
$MainOO = new MainOO("host","user","password","database");
?>
<div class="example">
<div class="example left">
<?php
$MainOO->User_Login();
?>
</div>
</div>
그것은 여전히 PHP를 & HTML을 혼합,하지만 HTML의 중간에 PHP의 힙을하는 것보다 깔끔한 많이의 지옥을 보이게합니다.
MVC 프레임 워크 (이 항목은 이미 설치되어 있음)로 이미 마이그레이션했거나 smarty와 같은 템플릿 엔진을 사용하여 마이그레이션 할 수 있다는 것을 알고 있지만 가능한 한 많이 피하고 싶습니다. 그래서 이것은 html 내에 더 깨끗한 PHP 코드를 갖는 실행 가능한 옵션입니까?
예 ....... ...... – user2092317
그것은 작동, 그렇지? 너에 따르면 더 좋아 보인다. 그렇지? 당신은 더 나은 대안을 알고 있습니다 ... 나는 거기에 무엇을 추가 할 지 확신하지 못합니다. – deceze
예 나는 완벽하다. –