调试模式
define(\'APP_DEBUG\',TRUE);
定义自动验证
protected $_validate = array( array(\'title\',\'require\',\'标题必须\'), );
查找读取数据
$Form = M(\'Form\'); // 读取数据 $data = $Form->find($id);//这里之所以用M方法而没有用D方法,是因为find方法是基础模型类Model中的方法,所以没有必要浪费开销去实例化FormModel类
获取某个字段的值
$title = $Form->where(\'id=3\')->getField(\'title\');
查询方式
1:$User->where(\'type=1 AND status=1\')->select(); 2://用数组 $User = M("User"); // 实例化User对象 $condition[\'name\'] = \'thinkphp\'; $condition[\'status\'] = 1; // 把查询条件传入查询方法 $User->where($condition)->select(); 3://用对象 $User = M("User"); // 实例化User对象 // 定义查询条件 $condition = new stdClass(); $condition->name = \'thinkphp\'; $condition->status= 1; $User->where($condition)->select(); 4://不同字段的不同查询条件 $User = M("User"); // 实例化User对象 $map[\'status&title\'] =array(\'1\',\'thinkphp\',\'_multi\'=>true); // 把查询条件传入查询方法 $User->where($map)->select();
获取变量
$id = $this->_get(\'id\'); // 获取get变量 $name = $this->_post(\'name\'); // 获取post变量 $value = $this->_session(\'var\'); // 获取session变量 $name = $this->_cookie(\'name\'); // 获取cookie变量 $file = $this->_server(\'PHP_SELF\'); // 获取server变量
定义路由规则:
\'URL_ROUTE_RULES\' => array( //定义路由规则 \'new/:id\d\' => \'News/read\', \'new/:name\' => \'News/read\', \'new/:year\d/:month\d\' => \'News/archive\', ),
访问时便可以用下面的地址:
http://serverName/index.php/new/8
跳转页面:
redirect(U("Form/regist"),1,"用户名不存在,即将跳转注册");
$this->redirect(U("Form/regist"),1,"用户名不存在,即将跳转注册");//这句只会打印出内容而不会跳转