boaphp
1.0.0
boaPHP is a free and open source, flexible and easy to use configuration PHP framework, with MVC design pattern, completely object-oriented, easy to learn and use, and easy to quickly develop.
Supports PHP version: PHP 7.0 - PHP 8.4 (the updates of small versions can be directly overwritten)
namespace mod docs controller ;
use boa boa ;
use boa msg ;
use boa controller ;
class index extends controller{
public function __construct (){
parent :: __construct ();
}
public function index (){
$ this -> view -> assign ( ' title ' , ' boaPHP开发手册' ); //模板赋值
$ this -> view -> html (); //从模板www/tpl/docs/index/index.html输出html
}
public function menu (){
$ model = boa:: model ( ' docs.content ' ); //访问docs模块中content模型
$ data = $ model -> list_content ( $ this -> cid ); //从模型获取数据
// GET/POST/COOKIE数据中的cid可以直接用$this->cid访问,配置验证规则后会自动验证
$ this -> view -> json ( $ data ); //输出json数据
}
}To verify the cid in the sample controller, you can configure mod/docs/variable/index/menu.php
return [
' cid ' => [
' label ' => '栏目ID ' , //标签名
' check ' => ' required ' , //检查规则:必需
' filter ' => ' intval ' //过滤规则:转为整型
]
]The class under the boa namespace can be accessed directly through the boa class
//使用默认或静态配置(config.php中配置)
boa:: cache ()-> xget ( ' language ' );
//动态配置一
boa:: cache ([ ' expire ' => 86400 ])-> get ( ' language ' );
//动态配置二
$ cookie = boa:: cookie ();
$ cookie -> cfg ( ' expire ' , 86400 );
$ cookie -> get ( ' language ' ); //后端调用其他控制器方法并返回结果,可以带参数
$ res = boa:: call ( ' news.content.show ' , [ ' id ' => 1 ]); //访问/mod/admin/library/test.php中get()方法
boa:: lib ( ' admin.test ' )-> get (); //访问database类,等同boa::database()
$ db = boa:: db ();
$ data = [ ' title ' => ' Title ' , ' content ' => ' Content ' ];
$ res = $ db -> table ( ' news ' )-> insert ( $ data ); //插入
$ res = $ db -> table ( ' news ' )-> where ( ' id = ? ' , $ id )-> delete (); //删除
$ res = $ db -> table ( ' news ' )-> where ( ' id = ? ' , $ id )-> update ( $ data ); //更新
//联合查询
$ arr = $ db -> table ( ' news A ' )
-> field ( ' A.*, B.category AS cat, COUNT(C.*) total ' )
-> join ( ' category B ' , ' A.cid = B.id ' )
-> join ( ' tag C ' , ' A.id = C.pid ' )
-> where ( ' A.cid = ? AND A.status = 1 ' , $ cid )
-> limit ( 50 , 10 )
-> order ( ' A.sort ASC, A.id DESC ' )
-> select ();
//单行查询
$ arr = $ db -> table ( ' news ' )-> where ( ' id = ? ' , $ id )-> find ();Template in the sample controller www/tpl/docs/index/index.html
{ inc inc . head } //包含inc/head.html
{ $arr news . content . show { $id } } //获取模型数据,参数$id
{ $i ++ }
{ list $arr $k $v } //循环输出$arr
{ $i ++ } : { $k } => { $v } < br > //自定义从1开始的序号
{ / list}
{ date Y - m - d { time } } //调用date函数,支持嵌套time函数
{ if { $var } == abc or ( $a > 1 && $b == 2 ) } //多条件判断
...
{ elseif { date Y - m - d } == 2020-02-02 || $c == 3 }
...
{ else }
...
{ / if}
{ @ news . error .1001 } //调用news模块语言包中error.php中1001标签 //调用boa内核语言包中error.php中2标签,带替换参数
boa:: lang ( ' boa.error.2 ' , ' home/controller/test.php ' );
//调用home模块语言包中news.php中title标签
boa:: lang ( ' home.news.title ' );