380 Star 2.5K Fork 618

GVPJohn / gf

 / 详情

新版控制器注册问题

已完成
创建于  
2018-08-08 16:12

刚用新版 发现和以前不太一样了 绑定控制器那块。比如 例子里面

s.BindController("/user",new(User))

绑定二级目录 不指定方法, 会默认走 Index 方法。
如果绑定的是根目录

s.BindController("/", new(User))

就不会走Index方法了。。
我原来旧版开发的代码是可以的。。

而且指定了 Index 方法 绑定到 / 上 也不行 提示 403

麻烦了

评论 (2)

kylexy 创建了任务
kylexy 更新了任务

示例代码 demo中的

改成注册根目录 / 就不能运行了

import (
	"gitee.com/johng/gf/g"
	"gitee.com/johng/gf/g/frame/gmvc"
)

type User struct {
	gmvc.Controller
}

func init() {
	s := g.Server()
	s.BindController("/",                       new(User))
	s.BindController("/user/{.method}/{uid}",       new(User), "Info")
	s.BindController("/user/{.method}/{page}.html", new(User), "List")
}

func (u *User) Index() {
	u.Response.Write("User")
}

func (u *User) Info() {
	u.Response.Write("Info - Uid: ", u.Request.Get("uid"))
}

func (u *User) List() {
	u.Response.Write("List - Page: ", u.Request.Get("page"))
}
kylexy 修改任务状态为进行中
kylexy 修改任务状态为待办的
John 修改任务状态为进行中

已修复

John 修改任务状态为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
1309327 johng 1705475649
Go
1
https://gitee.com/johng/gf.git
git@gitee.com:johng/gf.git
johng
gf
gf

搜索帮助