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课程以获取详细用途。