本文整理匯總了PHP中think\Model::map方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::map方法的具體用法?PHP Model::map怎麽用?PHP Model::map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Model
的用法示例。
在下文中一共展示了Model::map方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSave
public function testSave()
{
$config = $this->getConfig();
$order_model = new Model('order', $config);
$data = ['id' => '1', 'total' => '180.50', 'status' => 1, 'create_time' => time(), 'about' => ''];
\think\Config::set('db_fields_strict', false);
$info = $order_model->where(['id' => 1])->map('amount', 'total')->find();
$flag = $user_id = $order_model->map(['total' => 'amount'])->filter('trim')->save($data);
$this->assertSame(1, $flag);
\think\Config::set('db_fields_strict', true);
$data = ['status' => 1];
$flag = $order_model->where(['id' => 2])->setField($data);
$this->assertSame(1, $flag);
$flag = $order_model->where(['amount' => ['lt', 200]])->setField('freight_fee', 15);
$this->assertSame(1, $flag);
$map = ['amount' => ['gt', 300], 'freight_fee' => ['gt', 0]];
$flag = $order_model->where($map)->setDec('freight_fee', 5, 30);
$this->assertTrue($flag);
$flag = $order_model->where($map)->setInc('freight_fee', 5, 30);
$this->assertTrue($flag);
$flag = $order_model->where($map)->setDec('freight_fee', 5);
$this->assertSame(1, $flag);
$flag = $order_model->where($map)->setInc('freight_fee', 5);
$this->assertSame(1, $flag);
$ru_model = new Model('role_user', $config);
$data = ['user_id' => 1, 'role_id' => 1, 'remark' => 'remark'];
$info = $ru_model->where(['user_id' => 1])->find();
$flag = $ru_model->data($data)->save();
$this->assertSame(1, $flag);
}