zoukankan      html  css  js  c++  java
  • 两小时学Thinkphp3.1(多数来自thinkphp3.1快速入门)

    调试模式

    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/:idd'    => 'News/read',
    
        'new/:name'    => 'News/read',
    
        'new/:yeard/:monthd'  => 'News/archive',
    
    ),
    View Code

     

    访问时便可以用下面的地址:

    http://serverName/index.php/new/8

    跳转页面

    redirect(U("Form/regist"),1,"用户名不存在,即将跳转注册");
    $this->redirect(U("Form/regist"),1,"用户名不存在,即将跳转注册");//这句只会打印出内容而不会跳转
  • 相关阅读:
    博客园代码
    前端
    1338. Reduce Array Size to The Half
    1220. Count Vowels Permutation
    363. Max Sum of Rectangle No Larger Than K
    366. Find Leaves of Binary Tree
    443. String Compression
    8 · Rotate String
    886. Possible Bipartition
    LT 183 wood cut
  • 原文地址:https://www.cnblogs.com/cmj97/p/6341338.html
Copyright ? 2011-2022 开发猿


http://www.vxiaotou.com