本文整理汇总了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);
}
示例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);
}