-
Notifications
You must be signed in to change notification settings - Fork 18
gettingStarted introduction
- 按正式部署完成操作后, 根目录仅有include, index.php 和 license.txt
- 在index.php同级分别创建 model view ctrl 文件夹, 形成一个MVC架构模式
- 当然也可以使用其它模式
- 访问时, 控制层类名不是"serv"和"of"开头的, 默认会开启session, 详见 框架配置_of.session.autoStart 与 框架会话
<?php /** * 描述 : 入口文件, 支持面向过程开发 */ //框架唯一入口 require dirname(__FILE__) . '/include/of/of.php';//调用文本封装生成唯一值 echo of_base_com_str::uniqid(), "<br>\n"; //调用快捷方法查询SQL语句 print_r(L::sql('SELECT 1'));
fe6583ee08684d9587bac3b5b564f883 Array ( [0] => Array ( [1] => 1 ) )
<?php /** 模型层, 类的命名方式 规范注意第4条 / class model_test { /** 描述 : 返回传递前端的参数 / public static function argv() { return '后台参数传递到视图层'; } }
<?php /** 控制层 / class ctrl_test extends L { //L内提供了快速访问的方法,如数据库,语言包,组件等静态方法 继承后使用更方便 /** 描述 : 在入口文件中我们定义了默认请求方法为index / public function index() { //通过index.php?c=ctrl_test访问 echo '这个默认的加载方法'; }/** 描述 : 使用视图层 / public function view() { //通过index.php?c=ctrl_test&a=view访问 $this->view->argA = model_test::argv(); //向视图层传递数据,没继承L,可以操作 of_view::inst() 返回的对象 $this->view->argB = of_base_com_str::uniqid(); //生成唯一值 $this->view->argC = '<input>'; //属性不带下划线的会被编码 $this->view->_argD = '<input>'; //属性带下划线的不会被编码 $this->display('/test.html'); //加载视图模板,映射的方法是 of_view::display(模板路径) } } return true; //安全校验,允许访问的文件返回值必须与控制层校验值相同
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>使用模板引擎作为试图</title> </head> <body> <input _value="$this->argA" value="编译前"> <input _value="$this->argB" value="唯一值"> <!--<? echo $this->argC, $this->_argD; ?>--> </body> </html>
<input>
<?php /** 描述 : 控制层共享文件, 控制层文件与类名相同, 以$_GET['a']作为方法名(默认index) / //加载核心 require dirname(FILE) . '/include/of/of.php';//调度代码 if (isset($_GET['c'])) { //类名, 动作, 安全校验 $result = of::dispatch( strtr($GET['c'], '', '\'), //改成使用命名方式调用 isset($_GET['a']) ? $_GET['a'] : 'index', PHP_SAPI === 'cli' ? null : true ); //返回数组转成json if (is_array($result)) echo \of\base\com\data::json($result); //依然可以是 of_base_com_data 方式调用 }
<?php namespace model; /** 模型层 / class test { /** 描述 : 返回传递前端的参数 / public static function argv() { return '后台参数传递到视图层'; } }
<?php namespace ctrl; use of\base\com\str;/** 控制层 / class test extends \L { //L是根命名空间, 故需要用"" /** 描述 : 定义的默认请求方法为index / public function index() { echo '这个默认的加载方法'; }
/** 描述 : 使用视图层 / public function view() { $this->view->argA = \model\test::argv(); $this->view->argB = str::uniqid(); $this->display('/test.html'); } } return true;
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>使用模板引擎作为试图</title> </head> <body> <input _value="$this->argA" value="编译前"> <input _value="$this->argB" value="唯一值"> </body> </html>
手册地址 http://phpof.net/
- 入门指引
-
疑难解答
- 部署时会遇到的那些常见问题
简单却容易忽视 - 框架内置有哪些管理界面
生产模式进入界面需用 __OF_DEBUG__ - 如何定制不同的架构模式
通过配置入口文件中调度方法的参数即可 - 如何面向命名空间开发
of_xx 类可以按照命名空间方式调用 - 如何设置不同的部署模式
通过_of.debug设置 开发,测试,生产 模式 - 为什么控制层类文件要返回true
这是防止非法访问的方法之一 - 为什么传到视图层的变量会被编码
这是因为 XSS 安全防范的原因 - 为什么框架没有SQL构造器
因常规方案牺牲了性能又未很好解决问题 - 如何快速开发用户及权限管理功能
单点登录(SSO)模块因此而存在 - 怎么在系统的基础上扩展底层功能
三点: 扩展开发, 预先加载, 底层钩子 - 怎么使用 Composer 依赖管理工具
框架已集成, 默认关闭状态
- 部署时会遇到的那些常见问题
- 组件使用
- 集成插件
- 扩展开发
- 开发手册