????4. ????????
??????Phalcon?в?????????????????ORM???????????????PHQL?????ORM????????дSQL???????????????????????????????????ó?????????????????????PHQL?????????дPhalcon????SQL????????????????????дSQL?????????ORM???????????й????
????### 4.1 ???????
?????????????????????????????????????:
????????????????DatabaseController
????????????????InsertAction
??????InsertAction??д?????д???:
public function insertAction()
{
$customer = new Customer();
$customer->username = 'liyi';
$customer->password = '123456';
$ret = $customer->save();
if($ret){
print_r('??????');
} else {
print_r('???????');
}
}
????4.2 ???????
????1.find????
????Phalcon????????????find??????find?????????????з?????????????????:
public function findAction()
{
$customers = Customer::find();
$result = [];
foreach ($customers as $customer) {
$result[] = [
'username' => $customer->username??
'password' => $customer->password??
];
}
$this->response->setContentType('application/json'?? 'UTF-8');
return $this->response->setJsonContent($result);
}
?????????????????find()?????????customer????????????????????????????????????foreach???б????????????????????????????????????????????????????顣
????2.findFirst????
????Phalcon?е?findFirst??????find????????÷????????????????????findFirst?????????????????????????foreach????????????????????????????????????????username????????'liyi'??????
public function findfirstAction()
{
$customer = Customer::findFirst("username = 'liyi'");
$result = [
'username' => $customer->username??
'password' => $customer->password??
];
$this->response->setContentType('application/json'?? 'UTF-8');
return $this->response->setJsonContent($result);
}