phpcms v9二次开发之数据模型类
2013-03-12 12:52
477 查看
系统模型类:model.class.php
数据模型类的位置:/phpcms/libs/classes
phpcms v9二次开发中,我们要经常需要对模块的数据表进行查询、添加、修改和删除数据等操作,所有这些操作都离不开数据模型类model.class.php,它起到开发者与数据表的交互作用。model.class.php里面封装了许多数据表操作的方法,基本上常用的mysql操作语句都能从中找到,但是它又和原生态的mysql语句有所不同,和其它PHP内容管理系统一样,PHPCMS也对原生态的mysql语句进行封装简化,以使它操作起更加方便,为开发者省去了不少麻烦。具体我们来看一下model.class.php代码片断:
如上面的 select语,和mysql的select()有所不同,只要传入相关参数就可以实现mysql要用很多语句才能实现的功能。更多请看model.class.php。
模块模型类:数据表名称+'_model.class.php'
模块模型类的位置:phpcms/model/
在调用model.class.php里面的方法时,需要先把它实例化。每个模型对应一张数据表,每张数据表对应一个模块模型类。现在我们来建一个球队的模块模型表'fbteam',那么它对应的模型类为football_model.class.php,完整代码如下:
这样我们就建立好了一个球队模块的数据模型类。
本文首发WBlog博客,欢迎转载!转载请注明本文地址,谢谢。
本文地址:http://www.w3note.com/web/18.html
数据模型类的位置:/phpcms/libs/classes
phpcms v9二次开发中,我们要经常需要对模块的数据表进行查询、添加、修改和删除数据等操作,所有这些操作都离不开数据模型类model.class.php,它起到开发者与数据表的交互作用。model.class.php里面封装了许多数据表操作的方法,基本上常用的mysql操作语句都能从中找到,但是它又和原生态的mysql语句有所不同,和其它PHP内容管理系统一样,PHPCMS也对原生态的mysql语句进行封装简化,以使它操作起更加方便,为开发者省去了不少麻烦。具体我们来看一下model.class.php代码片断:
01 | <?php |
02 | pc_base::load_sys_class( 'db_factory' , '' , 0); |
03 | class model { |
04 |
05 | ... |
06 |
07 | public function __construct() { |
08 | if (!isset( $this ->db_config[ $this ->db_setting])) { |
09 | $this ->db_setting = 'default' ; |
10 | } |
11 | $this ->table_name = $this ->db_config[ $this ->db_setting][ 'tablepre' ]. $this ->table_name; |
12 | $this ->db_tablepre = $this ->db_config[ $this ->db_setting][ 'tablepre' ]; |
13 | $this ->db =db_factory::get_instance( $this ->db_config)->get_database( $this ->db_setting); |
14 | } |
15 |
16 | /** |
17 | * 执行sql查询 |
18 | * |
19 | * |
20 | * |
21 | * |
22 | * |
23 | * |
24 | * |
25 | */ |
26 | final public function select( $where = '' , $data = '*' , $limit = '' , $order = '' , $group = '' , $key = '' ) { |
27 | if ( is_array ( $where )) $where = $this ->sqls( $where ); |
28 | return $this ->db->select( $data , $this ->table_name, $where , $limit , $order , $group , $key ); |
29 | } |
30 | ... |
31 | } |
模块模型类:数据表名称+'_model.class.php'
模块模型类的位置:phpcms/model/
在调用model.class.php里面的方法时,需要先把它实例化。每个模型对应一张数据表,每张数据表对应一个模块模型类。现在我们来建一个球队的模块模型表'fbteam',那么它对应的模型类为football_model.class.php,完整代码如下:
01 | <?php |
02 |
03 | defined( 'IN_PHPCMS' ) or exit ( 'No permission resources.' ); |
04 |
05 | pc_base::load_sys_class( 'model' , '' , 0); //加载加载系统模型类model.class.php |
06 | class football_model extends model { //球队模型类football_model.class.php继承系统模型类model.class.php |
07 | public $table_name ; //声明一个数据表变量 |
08 | public function __construct() { //初始化球队模型类的构造函数 |
09 |
10 | $this ->db_config 'database' ); //加载数据库配置文件database.php |
11 |
12 | $this ->db_setting = 'default' ; //为数据库配置文件中配置数据库链接池名称,默认为default |
13 |
14 | $this ->table_name = 'fbteam' ; //'fbteam'为球队数据表的名称 |
15 |
16 | parent::__construct(); //调用父类model.class.php的构造函数,以获取父类的属性方法 |
17 |
18 | } |
19 |
20 | } |
21 |
22 | ?> |
本文首发WBlog博客,欢迎转载!转载请注明本文地址,谢谢。
本文地址:http://www.w3note.com/web/18.html
相关文章推荐
- phpcms v9二次开发之数据模型类
- phpcms v9二次开发之数据模型类
- phpcms v9二次开发之数据模型类
- K3 二次开发常用数据表
- PHPCMS 二次开发 子站与主站统一数据
- phpcms v9二次开发及使用中各种问题解决方案(一)
- 通达OA二次开发 小飞鱼OA工资上传数据模块开发(图文)
- PHPCMS V9二次开发便捷自定义后台入口文件夹
- 二次开发平台数据导入功能问题总结
- phpcms v9二次开发及使用中各种问题解决方案(二)
- 二次开发单据在“特殊数据权限”的业务对象授权列表中不显示
- 后台调度解析xml处理数据二次开发
- TFS二次开发的数据统计以PBI、Bug、Sprint等为例(一)
- Nginx二次开发(1.3)Nginx数据类型
- 地籍图 cad cass 二次开发 过滤器过滤扩展数据组码1000的解决方案
- PHPCMS V9二次开发自定义分页函数的方法分享
- PHPCMS V9二次开发自定义分页函数的方法
- 二次开发平台数据导入功能问题总结
- 服务器端二次开发标准事务保存数据
- 23个phpcms v9模板制作及二次开发常用代码案例