本文整理匯總了PHP中think\Model::field方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::field方法的具體用法?PHP Model::field怎麽用?PHP Model::field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Model
的用法示例。
在下文中一共展示了Model::field方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: doLogin
public function doLogin()
{
// 參數非法,則重新登錄
if (empty($_POST["name"]) || empty($_POST["password"]) || empty($_POST["code"])) {
$this->ajaxReturn(array("content" => null, "info" => "輸入不能為空", "status" => false));
exit(1);
}
//驗證碼生成
$code = $_POST['code'];
$Ver = new CodeController();
if (!$Ver->check_verify($code)) {
// 驗證碼錯誤
$this->ajaxReturn(array("content" => null, "info" => "驗證碼錯誤", "status" => false));
$this->error("驗證碼錯誤", "index");
exit(1);
}
//獲取用戶名
$username = $_POST['name'];
//獲取密碼
$password = $_POST["password"];
//創建systemmanager 的Model
$m = new Model("systemmanager");
//$res = $m->field ( "sys_password,sys_id" )->where ( "sys_username='{$username}'" )->select ();
$res = $m->field("sys_password,sys_id")->where("sys_username='%s'", $username)->select();
// 防注入 查找
if ($res[0]['sys_password'] == md5($password)) {
//若賬號和密碼都正確則登錄成功,並存入相關session
$_SESSION['systemmanager'] = $username;
$_SESSION['sys_id'] = $res[0]['sys_id'];
$this->ajaxReturn(array("content" => null, "info" => "登錄成功!", "status" => true));
}
//用戶名或者密碼錯誤,則登錄失敗
$this->ajaxReturn(array("content" => null, "info" => "用戶名或者密碼錯誤!", "status" => false));
}
示例2: testUnion
public function testUnion()
{
$config = $this->getConfig();
$user_model = new Model('user', $config);
$union = "SELECT consignee FROM __USER_ADDRESS__";
$result = $user_model->field('username')->union($union)->select();
$this->assertEquals(4, count($result));
$model = new Model('', $config);
$union = ["SELECT create_time FROM __ORDER__"];
$result = $model->table([$config['prefix'] . 'user'])->field('create_time')->union($union, true)->select();
$this->assertEquals(4, count($result));
}