英文:
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
负责验证,但我们如何控制表单的渲染呢?
英文:
I have created a model using the following code:
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)"`
}
Is there any way I can render a form directly using this structure? I think valid:required
rakes care of validation, but how do we control form rendering.
答案1
得分: 7
在控制器中:
func (this *AddController) Get() {
this.Data["Form"] = &UserProfile{}
this.TplNames = "index.tpl"
}
在模板中:
<form action="" method="post">
{{.Form | renderform}}
</form>
英文:
In controller:
func (this *AddController) Get() {
this.Data["Form"] = & UserProfile{}
this.TplNames = "index.tpl"
}
In template :
<form action="" method="post">
{{.Form | renderform}}
</form>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论