Sunhill Framework是一個簡單,快速且功能強大的PHP應用程序開發框架,它使您能夠使用MVC(模型 - 視圖 - 控制器)模式開發更現代的應用程序。
htaccess.txt文件的名稱更改為.htaccess (重要)System/Config.php並編輯數據庫,緩存和系統設置。有關更多詳細信息,請參見下文。
root
├── App
│ ├── Controllers
│ │ ├── Error.php
│ │ └── Home.php
│ ├── Models
│ │ ├── Error.php
│ │ └── Home.php
│ └── Views
│ ├── Error.php
│ └── Home.php
├── Core
│ ├── App.php
│ ├── Controller.php
│ ├── Model.php
│ └── View.php
├── Public
│ ├── cache
│ ├── css
│ ├── img
│ └── js
├── System
│ ├── Config.php
│ ├── SunCache.php
│ ├── SunDB.php
│ └── SunSitemap.php
├── .htaccess
├── index.php
└── init.php
App/Controller :在此文件夾中創建您的自定義控制器。
App/Models :在此文件夾中創建您的自定義模型。
App/Views :在此文件夾中創建自定義視圖。
Core :此文件夾包含主應用程序,模型,視圖和控制器文件。所有自定義模型,查看和控制器文件都從這些文件中繼承。如果真的不需要,請不要更改這些文件。
Public :將所有自定義文件(CSS,JS,IMG,Bootstrap等)上傳到此文件夾中。您的自定義視圖將使用這些文件。
System :此文件夾包含系統類和配置文件。僅在配置文件中進行更改。
打開System/Config.php文件並進行更改。
數據庫設置:
define ( ' DB_HOST ' , ' localhost ' ); // database host
define ( ' DB_PORT ' , ' 3306 ' ); // database port
define ( ' DB_DBNAME ' , '' ); // database name
define ( ' DB_USERNAME ' , '' ); // database username
define ( ' DB_PASSWORD ' , '' ); // database password緩存設置:
$ cacheConfig = [
' cacheDir ' => ' /../Public/cache ' , // cache folder path
' fileExtension ' => ' html ' , // cache file extension
' storageTime ' => 24 * 60 * 60 , // storage time (seconds)
' contentMinify ' => true , // content minification
' showTime ' => true , // show page load time
' sefUrl ' => true // website sef url status
];系統設置:
define ( ' SYS_PHPERR ' , true ); // php errors (show or hide, true / false)
define ( ' SYS_SYSERR ' , false ); // system errors (shor or hide, true / false)
define ( ' SYS_PGCACHE ' , false ); // page caching (true / false)
define ( ' SYS_CHEXCLUDE ' , []); // excluded pages for page caching (array)
define ( ' SYS_HOMEPAGE ' , ' home ' ); // home page (index, home, main, etc.)
define ( ' SYS_ERRPAGE ' , ' error ' ); // error page (if requested page does not exist, redirect to this page)樣本URL:
https://www.web_address.com/[controller_name]/[method_name]/[parameters]
調用頁面(控制器):
https://www.sunhillint.com/user
該地址將調用User控制器。
用操作(方法)調用頁面(控制器):
https://www.sunhillint.com/user/list
此地址將調用User控制器和執行list方法。
用操作(方法)和參數調用頁面(控制器):
https://www.sunhillint.com/user/update/3
此地址將使用3參數調用User控制器並執行update方法。
控制器響應用戶操作(提交表單,單擊鏈接等)。控制器是擴展Core Controller類的類。
控制器存儲在App/Controllers文件夾中。包括樣本主頁和錯誤控制器。控制器類需要在App/Controllers名稱空間中。您可以添加子目錄來組織控制器,因此在為這些控制器添加路由時,您需要指定名稱空間。
示例控制器文件內容(無數據庫訪問,靜態頁面):
public function show () {
require_once ( $ this -> view ); // include view file (with $result content)
}示例控制器文件內容(具有數據庫訪問,動態頁面):
public function show () {
if (! empty ( $ this -> model )) { // if this page needs database
$ result = ( $ this -> model )-> show (); // call model class' show method
}
require_once ( $ this -> view ); // include view file (with $result content)
}控制器類包含作為操作的方法。要創建一個操作,請在控制器中添加方法名稱,然後將其用於URL(路由參數)。
樣本URL:
https://www.web_address.com/[controller_name]
所有頁面都必須具有控制器文件,並且show方法必須在其中。
視圖用於顯示信息。查看文件進入App/Views文件夾。視圖文件中不應發生數據庫訪問或類似的內容。
視圖擴展了CoreView類,如果您的視圖(頁面)需要數據庫訪問,則您的值將從控制器文件轉發。
示例查看多個記錄的文件內容(內部HTML標籤):
foreach ( $ result as $ row ) {
echo " ... " ;
}或(一份記錄):
echo $ result [ 0 ][ ' content ' ];所有頁面都必須具有視圖文件。
模型用於將數據獲取並存儲在您的應用程序中。他們對這些數據將如何在視圖中顯示。模型擴展了CoreModel類,並使用PDO訪問數據庫(包括SUNDB類)。它們存儲在App/Models文件夾中。
所有頁面都必須具有模型文件(即使是空),並且show方法必須在其中。
通過主要模型使用SUNDB PDO類:
$ result = $ this -> query ( ' SELECT * FROM table_name ' ); // send query to the main model
return $ result ; // return the result to the controller直接使用SUNDB PDO類:
$ result = ( $ this -> pdo )-> select ( ' table_name ' )
-> run (); // select all records from the table
return $ result ; // return the result to the controller請參閱SUNDB PDO課程以獲取詳細用途。
該框架包括一個特殊的頁面緩存系統(SunCache類)。
緩存系統可以在System/Config.php文件中激活/停用:
define ( ' SYS_PGCACHE ' , true ); // page caching (true / false)可以在System/Config.php文件中定義排除的頁面:
define ( ' SYS_CHEXCLUDE ' , [ ' home ' , ' error ' ]); // excluded pages for page caching (array)可以在System/Config.php文件中更改緩存設置:
$ cacheConfig = [
' cacheDir ' => ' /../Public/cache ' , // cache folder path
' fileExtension ' => ' html ' , // cache file extension
' storageTime ' => 24 * 60 * 60 , // storage time (seconds)
' contentMinify ' => true , // content minification
' showTime ' => true , // show page load time
' sefUrl ' => true // website sef url status
];請參閱SunCache課程以獲取詳細用途。