function edit()
{
if (!empty($_POST['name'])) {
$inserts['name'] = $_POST['name'];
$inserts['intro'] = $_POST['intro'];
$msg['code'] = 0;
if (empty($_POST['id'])) {
$res = table("project")->put($inserts);
$msg['message'] = $res ? "添加成功,ID: " . $res : "添加失败";
} else {
$res = table("project")->set(intval($_POST['id']), $inserts);
$msg['message'] = $res ? "修改成功" : "修改失败";
}
$this->assign('msg', $msg);
}
if (empty($_GET)) {
$form['name'] = \Swoole\Form::input('name');
$form['intro'] = \Swoole\Form::input('intro');
$this->assign('form', $form);
} else {
$id = (int) $_GET['id'];
$res = table("project")->get($id)->get();
$form['name'] = \Swoole\Form::input('name', $res['name']);
$form['intro'] = \Swoole\Form::input('intro', $res['intro']);
$form['id'] = \Swoole\Form::hidden('id', $res['id']);
}
$this->assign('form', $form);
$this->display();
}