本文整理匯總了PHP中think\Model::limit方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::limit方法的具體用法?PHP Model::limit怎麽用?PHP Model::limit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Model
的用法示例。
在下文中一共展示了Model::limit方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: limit
public function limit($limit, $length = NULL)
{
if (!$limit) {
return $this;
}
return parent::limit($limit, $length);
}
示例2: testJoin
public function testJoin()
{
$config = $this->getConfig();
$user_model = new Model('user', $config);
$join = [[['order o', 'tp_'], 'u.id=o.user_id'], [['user_address' => 'a'], 'u.id=a.user_id']];
$result = $user_model->alias('u')->join($join)->field('u.username,a.consignee,o.amount')->select();
$data = ['username' => 'test', 'consignee' => '張三', 'amount' => '200'];
$this->assertEquals($data, $result[0]);
$result = $user_model->alias('u')->join('__USER_ADDRESS__ a', 'u.id=a.user_id', 'left')->field('u.username,a.consignee')->select();
$data = ['username' => 'test', 'consignee' => '張三'];
$this->assertEquals($data, $result[0]);
$result = $user_model->alias('u')->join('role_user ru', 'u.id=ru.user_id', 'left')->field('u.username,ru.role_id')->select();
$data = ['username' => 'test', 'role_id' => '1'];
$this->assertEquals($data, $result[0]);
$order_model = new Model('order', $config);
$subsql = $order_model->limit(1)->buildSql();
$result = $user_model->alias('u')->join($subsql . ' o', 'u.id=o.user_id', 'left')->field('u.username,o.amount')->select();
$data = ['username' => 'test', 'amount' => '200'];
$this->assertEquals($data, $result[0]);
// 兼容_join方法
$result = $user_model->alias('u')->join('__USER_ADDRESS__ a on u.id=a.user_id', 'left')->field('u.username,a.consignee')->select();
$data = ['username' => 'test', 'consignee' => '張三'];
$this->assertEquals($data, $result[0]);
}