thinksns功能开发说明

上传人:xiao****1972 文档编号:84088124 上传时间:2019-03-02 格式:DOC 页数:7 大小:80KB
返回 下载 相关 举报
thinksns功能开发说明_第1页
第1页 / 共7页
thinksns功能开发说明_第2页
第2页 / 共7页
thinksns功能开发说明_第3页
第3页 / 共7页
thinksns功能开发说明_第4页
第4页 / 共7页
thinksns功能开发说明_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《thinksns功能开发说明》由会员分享,可在线阅读,更多相关《thinksns功能开发说明(7页珍藏版)》请在金锄头文库上搜索。

1、ThinkSNS功能开发说明ThinkSNS是一个开源的交友社区化网络引擎。ThinkSNS源于办公圈项目,WEB端基于ThinkPHP框架开发。还使用了JQuery的AJAX框架。主要说明一下功能开发要用到的东西。举个例子,要添加一个送礼物的功能,我们叫它Gift.用到以下4个部份:页面JS页面处理上的一些JS,会统一放到/public/js/model/Gift.js,Gift功能的页面会包含这个js。相关js参考相关文档,ajax方面参考JQuery文档。页面模板模板使用ThinkPHP自带的模板引擎。功能开发的模板放在/sns/tpl/default/下面,而我们礼物功能的就放在Gif

2、t文件夹下,可以看到有 all.html friends.html index.html receivebox.html sendbox.html success.html,这些模板文件都会和第三部份说到的Action类的方法一一对应。首先我们修改下 Action 的 index操作方法,添加模板赋值和渲染模板操作。 class IndexAction extends Action public function index() $Blog = new BlogModel(); $list = $Blog-findAll(); $this-assign(title, ThinkPHP 示例);

3、$this-assign(list,$list); $this-display(); 创建一个 index.html 模板文件,内容如下: $title $vo.title $vo.content IndexAction 类的index 方法里面使用 $this-display(); 输出页面的时候,会自动读取 TpldefaultIndexindex.html 模板文件来输出。 现在我们再次在浏览器里面输入 http:/localhost/myApp/ 就可以看到动态数据的输出了,注意看页面的 Title文字的变化。处理部分(Action)Action放在/sns/lib/action 目录

4、下,类名和文件名是一致的,并且类文件都是以.class.php 为后缀。而 IndexAction 类就表示 了 Index 模块。index 操作其实就是IndexAction类的一个方法,所以我们在浏览器里面输入 URL http:/localhost/sns/index.php/Index/index/ 的时候其实就是执行了 IndexAction类的 index(公共)方法,因此我们看到了输出的结果。我们来 新增一个操作方法 show。 class IndexAction extends Action public function show() echo 这是新的 show 操作;

5、然后在浏览器里面输入 http:/localhost/sns/index.php/Index/show/ 我们就可以看到刚才定义的输出了。Action API常用方法说明ajaxReturn Ajax方式返回数据到客户端 access: public void ajaxReturn (mixed$data = , String$info = , String$status = , $type = ) mixed $data: 要返回的数据 String $info: 提示信息 String $status: ajax返回类型 JSON XML $type assign 模板变量赋值 acces

6、s: public void assign (mixed$name, mixed$value = ) mixed $name: 要显示的模板变量 mixed $value: 变量的值 display 模板显示调用内置的模板引擎显示方法, access: public void display (string$templateFile = , string$charset = , string$contentType = text/html, string$varPrefix = ) string $templateFile: 指定要调用的模板文件 默认为空 由系统自动定位模板文件 string

7、 $charset: 输出编码 string $contentType: 输出类型 string $varPrefix: 模板变量前缀 数据库交互(Model)在数据库创建了 think_blog表之后,现在我们在 LibModel 目录下面创建一个 BlogModel.class.php 文件,内容如下: class BlogModel extends Model 只需要建立一个空的BlogModel 类就可以了,我们就可以完成常用的数据存取操作了。 定义了模型类,我们还需要修改 Action类的操作方法,来获取数据并显示出来。 我们把原来自动生成的 index 操作方法修改成下面的代码:

8、class IndexAction extends Action public function index() $Blog = new BlogModel(); $list = $Blog-findAll(); dump($list); 然后我们就可以在浏览器里面输入下面的 URL 访问 index 操作 http:/localhost/sns/Model API常用方法clear 清空表数据 throws: ThinkExecption access: public boolen clear () count 统计满足条件的记录个数 access: public integer count

9、 (mixed$condition = , string$field = *) mixed $condition: 条件 string $field: 要统计的字段 默认为* delete 根据条件删除表数据如果成功返回删除记录个数 throws: ThinkExecption access: public boolen delete (mixed$data = null, integer$limit = , string$order = , boolean$autoLink = false) mixed $data: 删除条件 integer $limit: 要删除的记录数 string $

10、order: 删除的顺序 boolean $autoLink: 是否关联删除 deleteAll 根据条件删除数据 throws: ThinkExecption access: public boolen deleteAll (mixed$condition = , boolean$autoLink = false) mixed $condition: 删除条件 boolean $autoLink: 是否关联删除 execute 执行SQL语句 return: | integer throws: ThinkExecption access: public false execute (stri

11、ng$sql = ) string $sql: SQL指令 find 根据条件得到一条记录 throws: ThinkExecption access: public mixed find (mixed$condition = , string$fields = *, boolean$cache = false, mixed$relation = false, boolean$lazy = false) mixed $condition: 条件 string $fields: 字段名,默认为* boolean $cache: 是否读取缓存 mixed $relation: 是否关联查询 boo

12、lean $lazy: 是否惰性查询 findAll 查找记录 throws: ThinkExecption access: public ArrayObject|ResultIterator findAll (mixed$condition = , string$fields = *, string$order = , string$limit = , string$group = , string$having = , string$join = , boolean$cache = false, mixed$relation = false, boolean$lazy = false) m

13、ixed $condition: 条件 string $fields: 查询字段 string $order: 排序 string $limit string $group string $having string $join boolean $cache: 是否读取缓存 mixed $relation: 是否关联查询 boolean $lazy: 是否惰性查询 first 获取满足条件的第一条记录 access: public mixed first (mixed$condition = , string$order = , string$fields = *, boolean$relation = false) mixed $condition: 条件 string $fields: 字段名,默认为* string $order: 排序 boolean $relation: 是否读取关联 query SQL查询 throws: ThinkExecption access: public ArrayObject|ResultIterator query (string$sql, boolean$cache = false, boolean$lazy = false) string $sql: SQ

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号