当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::auto方法代码示例

本文整理汇总了PHP中think\Model::auto方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::auto方法的具体用法?PHP Model::auto怎么用?PHP Model::auto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在think\Model的用法示例。


在下文中一共展示了Model::auto方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFill

 public function testFill()
 {
     $model = new Model('', $this->getConfig());
     $data = ['username' => '', 'nickname' => 'nickname', 'phone' => ' 123456', 'hobby' => ['1', '2'], 'cityid' => '1', 'a' => 'a', 'b' => 'b'];
     $auto = ['user' => ['__option__' => ['value_fill' => 'username,password,phone', 'exists_fill' => 'nickname'], 'username' => ['strtolower', 'callback'], 'password' => ['md5', 'callback'], 'nickname' => [[&$this, 'fillName'], 'callback', 'cn_'], 'phone' => function ($value, $data) {
         return trim($value);
     }, 'hobby' => ['', 'serialize'], 'cityid' => ['1', 'ignore'], 'address' => ['address'], 'integral' => 0, ['reg_time', 'time', 'callback'], ['login_time', function ($value, $data) {
         return $data['reg_time'];
     }], 'ab' => ['a,b', 'serialize']]];
     \think\Config::set('auto', $auto);
     $result = $model->auto('user')->create($data);
     $data['nickname'] = 'cn_nickname';
     $data['phone'] = '123456';
     $data['hobby'] = serialize($data['hobby']);
     $data['address'] = 'address';
     $data['integral'] = 0;
     $data['reg_time'] = time();
     $data['login_time'] = $data['reg_time'];
     $data['ab'] = serialize(['a' => 'a', 'b' => 'b']);
     unset($data['cityid'], $data['a'], $data['b']);
     $this->assertEquals($data, $result);
     // 测试带.和*的键名
     $data = ['name' => ['a' => 'a', 'b' => 'b'], 'goods' => [0 => [0 => ['item' => 'item', 'price' => ''], 1 => ['item' => 'item2', 'price' => '']]]];
     $test = ['name.*' => 'name', 'goods.*.*.price' => 100];
     $result = $model->auto($test)->create($data);
     $data['name']['a'] = $data['name']['b'] = 'name';
     $data['goods'][0][0]['price'] = 100;
     $data['goods'][0][1]['price'] = 100;
     $this->assertEquals($data, $result);
 }
开发者ID:Lofanmi,项目名称:think,代码行数:30,代码来源:modelTest.php

示例2: testFill

 public function testFill()
 {
     $model = new Model('', $this->getConfig());
     $data = ['username' => '', 'nickname' => 'nickname', 'phone' => ' 123456', 'cityid' => '1', 'a' => 'a', 'b' => 'b'];
     $auto = ['user' => ['__option__' => ['scene' => ['edit' => 'username,nickname,phone,hobby,cityid,address,integral,reg_time,login_time,ab'], 'value_fill' => 'username,phone', 'exists_fill' => 'nickname'], 'username' => ['strtolower', 'callback'], 'password' => ['md5', 'callback'], 'nickname' => [[&$this, 'fillName'], 'callback', 'cn_'], 'phone' => function ($value, $data) {
         return trim($value);
     }, 'cityid' => ['1', 'ignore'], 'address' => ['address'], 'integral' => 0, ['reg_time', 'time', 'callback'], ['login_time', function ($value, $data) {
         return $data['reg_time'];
     }], 'ab' => ['a,b', 'serialize']]];
     Config::set('auto', $auto);
     $result = $model->auto('user.edit')->create($data);
     $data['nickname'] = 'cn_nickname';
     $data['phone'] = '123456';
     $data['address'] = 'address';
     $data['integral'] = 0;
     $data['reg_time'] = time();
     $data['login_time'] = $data['reg_time'];
     $data['ab'] = serialize(['a' => 'a', 'b' => 'b']);
     unset($data['cityid'], $data['a'], $data['b']);
     $this->assertEquals($data, $result);
 }
开发者ID:cnzin,项目名称:think,代码行数:21,代码来源:modelTest.php


注:本文中的think\Model::auto方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。