·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> thinkphp笔记

thinkphp笔记

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
thinkphp笔记M 项目目录/应用目录/Lib/ModelV 项目目录/应用目录/TplC 项目目录/应用目录/Lib/Action1.PATHINFO 模式 http://域名/项目名/入口文件/模块名/方法名/键1/值1/键2/值22.普通模式 http://域名/项目名/入口文件?m=模块名&a=方法名&键1=值1&键2=值23.REWRITE模块 http://域名/项目名/模块名/方法名/键1/值1/键2/值24.兼容模式 http://域名/项目名/入口文件?s=模块名/方法名/键1/值1/键2/值2<?php//本类由系统自动生成,仅供测试用途classIndexActionextendsAction{publicfunctionindex(){ echo"helloworld";} publicfunctionadd(){ echo"你好,吴昊<br>"; echo '你好'.$_GET['name'].'你的年龄是'.$_GET['age']; }}http://localhost/test/index.php/Index/add?name=wuhaohttp://localhost/test/index.php/Index/add/name/wuhaohttp://localhost/test/index.php/Index/add/name/wuhao/age/18

'URL_PATHINFO_DEPR'=>'-', //修改URL的分隔符

'TMPL_L_DELIM'=>'<{', //修改左定界符'TMPL_R_DELIM'=>'}>', //修改右定界符http://localhost/test/index.php/Index-add-name-wuhao-age-23http://localhost/test/index.php/Index/indexhttp://localhost/test/index.php/Index/addpublic function add(){ /*echo "你好,吴昊<br>"; echo '你好'.$_GET['name'].'你的年龄是'.$_GET['age'];*/ $name='吴昊'; $this->assign('myname',$name); //$this->myname='abc'; $this->display();}<meta http-equiv="content-type" content="text/html;charset=utf-8">一些动态的数据可以通过assign()方法分配给模板显示<h1>访问了add方法。</h1><p>你好!{$myname}</p>D:\wamp\www\test\App\Tpl\Index需要在方法中通过new Model(表名)的形式操作数据库 $m=new Model('User'); $arr=$m->select();'DB_TYPE'=>'MySQL', //设置数据库类型'DB_HOST'=>'localhost',//设置主机'DB_NAME'=>'thinkphp',//设置数据库名'DB_USER'=>'root', //设置用户名'DB_PWD'=>'', //设置密码'DB_PORT'=>'3306', //设置端口号'DB_PREFIX'=>'tp_', //设置表前缀'DB_DSN'=>'mysql://root:@localhost:3306/thinkphp',//使用DSN方式配置数据库信息 ,优先级比传统方式高$user=new Model('User'); $arr=$user->select(); var_dump($arr); $this->display();'SHOW_PAGE_TRACE'=>true,//开启页面Trace还有一种简单实用模型的方式M() 等效为 new Model();$m=M('User');$arr=$m->select();使用模型的实例可以对数据进行操作,操作的工作一般就是对数据库进行 增删改查 CURD增 -C Create $m->add()删 -D Delete $m->delete()改 -U Update $m->save()查 -R Read $m->select()a、模板可以遍历数组<volist name='data' id='vo'> {$vo.id}----{$vo.username}-----{$vo.sex}<br/> </volist>b、我们可以开启调试功能中的page_trace 1.开启调试功能 define('APP_DEBUG',true); 2.我们需要设置配置文件,开启页面trace 'SHOW_PAGE_TRACE'=>true,//开启页面Trace读取数据对数据的读取 Read$m=new Model('User');$m=M('User');select:$m->select(); //获取所有数据,以数组形式返回find:$m->find($id); //获取单条数据getField(字段名) //获取一个具体的字段值$arr=$m->where('id=2')->getField('username');创建数据 对数据的添加 Create$m=new Model('User');$m=M('User');$m->字段名=值$m->add(); 返回值是新增的id号删除数据 $m=M('User');$m->delete(2); //删除id为2的数据$m->where('id=2')->delete(); 返回值是受影响行数更新数据$m=M('User');$data['id']=1;$data['username']='ztz2';$m->save($data); 返回值是受影响行数CURD演示:==================================================================================================================================================================================================查询方式:一、普通查询方式a、字符串 $arr=$m->where("sex=0 and username='gege'")->find();b、数组 $data['sex']=0; $data['username']='gege'; $arr=$m->where($data)->find(); 注意:这种方式默认是and的关系,如果使用or关系,需要添加数组值:$data['_logic']='or';二、表达式查询方式 $data['id']=array('lt',6); $arr=$m->where($data)->select(); EQ 等于,NEQ不等于,GT 大于,EGT大于等于,LT 小于,ELT小于等于,LIK