The Wayback Machine - https://web.archive.org/web/20190601131614/https://github.com/kataras/iris/issues/1205
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVC with parameters and context #1205

Open
apuckey opened this issue Feb 27, 2019 · 2 comments

Comments

@apuckey
Copy link

commented Feb 27, 2019

According to the documentation iris.Context can be passed in as the first argument to a MVC function like so:

type Controller struct {}

func (c *Controller) BeforeActivation(b mvc.BeforeActivation) {
	b.Handle("GET", "/test", "Get")
	b.Handle("GET", "/test/{id:string}", "GetById")
}

func (c *Controller) Get(ctx iris.Context) mvc.Result {
	return mvc.Response{
		ContentType: "application/json",
		Text:        "{\"welcome\": true}",
	}
}

func (c *Controller) GetById(ctx iris.Context, id string) mvc.Result {
	return mvc.Response{
		ContentType: "application/json",
		Text:        "{\"welcome\": false}",
	}
}

Using the Get() function works however using GetById is resulting in an application panic:

[WARN] 2019/02/27 17:00 Recovered from a route's Handler('github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2')
At Request: 200 /test/stre GET ::1
Trace: reflect: Call using zero Value argument

I'm registering the controller as follows:

mvc.New(app).Handle(new(test.Controller))
@kataras

This comment has been minimized.

Copy link
Owner

commented Feb 27, 2019

Hello @apuckey,

This is expected failure because you don't need the path parameter's bindable input arguments((id string) mvc.Result ...) when you bind the Context itself (which contains those via ctx.Params()...). And in the other hand you don't need to require Context at method level, you can move it to your controller and it will be available via c.Ctx.

You are the first dev raised this as an issue, however I agree with you, you expected something else and something other happened. Give me a chance to, at least, fix that behavior on the upcoming release.

Thank you,
Gerasimos Maropoulos

@apuckey

This comment has been minimized.

Copy link
Author

commented Feb 27, 2019

No worries,

Thanks!

@kataras kataras added this to the v11.2.0 milestone Mar 1, 2019

kataras added a commit that referenced this issue Mar 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.