Beego - 创建模型表单和 ORM
Beego - Creating Model Form and ORM
我使用以下代码创建了一个模型:
type UserProfile struct {
Id int `orm:"auto"`
Name string `orm:"size(100)"`
Email string `orm:"size(100)"`
Type string `orm:"size(30)"`
Admin bool
Car []*Car `orm:"reverse(many)"`
}
有什么方法可以直接使用此结构呈现表单吗?我认为 valid:required
关注验证,但我们如何控制表单呈现。
在控制器中:
func (this *AddController) Get() {
this.Data["Form"] = & UserProfile{}
this.TplNames = "index.tpl"
}
在模板中:
<form action="" method="post">
{{.Form | renderform}}
</form>
我使用以下代码创建了一个模型:
type UserProfile struct {
Id int `orm:"auto"`
Name string `orm:"size(100)"`
Email string `orm:"size(100)"`
Type string `orm:"size(30)"`
Admin bool
Car []*Car `orm:"reverse(many)"`
}
有什么方法可以直接使用此结构呈现表单吗?我认为 valid:required
关注验证,但我们如何控制表单呈现。
在控制器中:
func (this *AddController) Get() {
this.Data["Form"] = & UserProfile{}
this.TplNames = "index.tpl"
}
在模板中:
<form action="" method="post">
{{.Form | renderform}}
</form>