thinkphp实例教程之数据分页
2,新建一个thinkphp项目。新版tp已经内置了项目自动生成目录功能。 在htdocs(也就是你的网站根目录)下新建一个test文件夹,把thinkphp核心文件夹放进test根目录,并在test根目录新建文件index.php,加入如下代码:
运行“http://localhost/test/index.php”.会看到thinkphp的欢迎页面。再打开你的test目录看看,发现在根目录下多了一个test文件夹,此时,你的项目目录已经生成了。 打开/test/test/conf/目录,新建“config.php” ,配置好数据库连接。
如果想打开调试模式,请在数组中加入: "debug_mode"=>true 3,基本页面输入与输出的实现。 1)打开/test/test/lib/action/indexaction.class.php,找到:
由系统自动生成的indexaction类中的index()函数是默认的首页调用函数。你可以使用http://localhost/test/index.php或者http://localhost/test/index.php/index来访问他 2)暂时不管他。首先,需要一个表单提交的页面。打开“/test/test/tpl/default/index/”,新建一个文件add.html. 保存后,输入 http://localhost/test/index.php/index/add,你就能看到你新增的页面了。其中,__url__(url要大写)被转换为相应地址/test/index.php/index/. 这里简单说一下模板和action之间的关系。每一个action,对应的模板是与之名字相同的html文件。例如index类下的index(),对应default/index/index.html,而add.html,则显然对应的是index类下的add()。 可以在只有add.html而没有相应的add()动作情况下,用访问add()的形式(http://localhost/test/index.php/index/add)来访问add.html模板。 add.html模板下的占位符会被替换成相应的数据。(脚本学堂 编辑整理 bbs.it-home.org) 3)从form的“action=__url__/insert”中可以看出,进行表单处理的动作是/test/index.php/index/insert,所以我们得新增insert动作来处理表单提交数据。在此之前,我们还有一件重要的事情要做,那就是新增model文件。通过model文件的建立,我们将能在insert动作中使用便捷的方法来操作数据库了 打开/test/test/lib/model/文件夹,新建文件testmodel.class.php.打开他,输入并保存以下代码
这是activerecord实现的基本文件。 命名规则是你数据库中的表后面加model。 例如将要使用到的表是test,文件命名必须是testmodel.class.php,而文件下的类命名必须是testmodel. 接着,回到indexaction.class.php文件,删除原来的代码,加入:
4)接下来,需要在indexaction类中增加一个首页默认显示动作index()来调用表单数据。
设置一个模板,在/test/test/tpl/default/index/下新建index.html(因为默认对应了index()。 程序中可以直接assign.而不用去指定模板文件。当然,这是可以配置的。)
保存,输入 http://localhost/test/ 以上就是thinkphp制作分页的方法与实例,希望对大家有所帮助。 |
上一篇: EC2上MySQL如何开启远程访问
下一篇: 详解python装饰器的实例教程
推荐阅读
-
windows phone开发之 listbox分页加载数据
-
ThinkPHP 3.2 数据分页代码分享
-
thinkPHP5框架数据库连贯操作之cache()用法分析
-
海量数据库的查询优化及分页算法方案 2 之 改良SQL语句
-
thinkphp5.x之数据库操作相关解析 Db类
-
ThinkPHP验证码和分页实例教程
-
2019年6月14日 Web框架之Django_07 进阶操作(MTV与MVC、多对多表三种创建方式、前后端传输数据编码格式contentType、ajax、自定义分页器)
-
Vue单页面开发实例之数据列表+分页+时间筛选+类型选择及后台实现
-
THINKPHP5分页数据对象处理过程解析
-
Thinkphp 框架扩展之数据库驱动常用方法小结