├── README.md ├── htaccess.txt ├── index.php ├── mvc ├── Bridge.php ├── controllers │ └── Home.php ├── core │ ├── App.php │ ├── Controller.php │ └── DB.php ├── htaccess.txt ├── models │ └── SinhVienModel.php └── views │ ├── aodep.php │ ├── aoxau.php │ └── pages │ ├── contact.php │ └── news.php └── public └── htaccess.txt /README.md: -------------------------------------------------------------------------------- 1 | # HƯỚNG DẪN SET UP PROJECT PHP THEO MÔ HÌNH MVC 2 | 3 | Hướng dẫn từng bước set up một project PHP theo mô hình MVC. 4 | Bạn có thể sử dụng source này để tiết kiệm thời gian set up cho project của mình. 5 | 6 | * Buổi 1: Giới thiệu mô hình MVC 7 | https://www.youtube.com/watch?v=CasgqSBvOMY 8 | 9 | * Buổi 2: Controllers 10 | https://www.youtube.com/watch?v=JJ97y6OviRk 11 | 12 | * Buổi 3: Models 13 | https://www.youtube.com/watch?v=VCn6yu6eaFs 14 | 15 | * Buổi 4: Views 16 | https://www.youtube.com/watch?v=5JOgsWOS-CM 17 | 18 | * Buổi 5: Kết nối Database 19 | https://www.youtube.com/watch?v=guCJ0o2rUZ8 20 | 21 | * Buổi 6: Các vấn đề khác (Ajax, Route...) 22 | https://www.youtube.com/watch?v=TutBjMexFE4 23 | 24 | - Khóa học lập trình PHP tại Khoa Phạm: https://khoapham.vn/lap-trinh-php.html 25 | - Group học lập trình: https://www.facebook.com/groups/khoaphamonline 26 | - Website học lập trình online: http://online.khoapham.vn 27 | 28 | -------------------------------------------------------------------------------- /htaccess.txt: -------------------------------------------------------------------------------- 1 | RewriteEngine On 2 | RewriteCond %{REQUEST_FILENAME} !-d 3 | RewriteCond %{REQUEST_FILENAME} !-f 4 | 5 | RewriteRule ^(.+)$ index.php?url=$1 6 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mvc/Bridge.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mvc/controllers/Home.php: -------------------------------------------------------------------------------- 1 | model("SinhVienModel"); 10 | echo $teo->GetSV(); 11 | 12 | } 13 | 14 | function Show($a, $b){ 15 | // Call Models 16 | $teo = $this->model("SinhVienModel"); 17 | $tong = $teo->Tong($a, $b); // 3 18 | 19 | // Call Views 20 | $this->view("aodep", [ 21 | "Page"=>"news", 22 | "Number"=>$tong, 23 | "Mau"=>"red", 24 | "SoThich"=>["A", "B", "C"], 25 | "SV" => $teo->SinhVien() 26 | ]); 27 | } 28 | } 29 | ?> -------------------------------------------------------------------------------- /mvc/core/App.php: -------------------------------------------------------------------------------- 1 | UrlProcess(); 11 | 12 | // Controller 13 | if( file_exists("./mvc/controllers/".$arr[0].".php") ){ 14 | $this->controller = $arr[0]; 15 | unset($arr[0]); 16 | } 17 | require_once "./mvc/controllers/". $this->controller .".php"; 18 | $this->controller = new $this->controller; 19 | 20 | // Action 21 | if(isset($arr[1])){ 22 | if( method_exists( $this->controller , $arr[1]) ){ 23 | $this->action = $arr[1]; 24 | } 25 | unset($arr[1]); 26 | } 27 | 28 | // Params 29 | $this->params = $arr?array_values($arr):[]; 30 | 31 | call_user_func_array([$this->controller, $this->action], $this->params ); 32 | 33 | } 34 | 35 | function UrlProcess(){ 36 | if( isset($_GET["url"]) ){ 37 | return explode("/", filter_var(trim($_GET["url"], "/"))); 38 | } 39 | } 40 | 41 | } 42 | ?> -------------------------------------------------------------------------------- /mvc/core/Controller.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mvc/core/DB.php: -------------------------------------------------------------------------------- 1 | con = mysqli_connect($this->servername, $this->username, $this->password); 13 | mysqli_select_db($this->con, $this->dbname); 14 | mysqli_query($this->con, "SET NAMES 'utf8'"); 15 | } 16 | 17 | } 18 | 19 | ?> -------------------------------------------------------------------------------- /mvc/htaccess.txt: -------------------------------------------------------------------------------- 1 | Options -Indexes -------------------------------------------------------------------------------- /mvc/models/SinhVienModel.php: -------------------------------------------------------------------------------- 1 | con, $qr); 14 | } 15 | 16 | } 17 | ?> -------------------------------------------------------------------------------- /mvc/views/aodep.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |