• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Clean way for json responses

R

ragtek

Guest
#1
What should i do, if i have a controllermethod, which returns only json data?

I've seen that xenforo is using "non existing templates for this.

For example:
PHP:
return $this->responseView(
            'XenForo_ViewPublic_Member_Find',
            'member_autocomplete',
            $viewParams
        );
template member_autocomplete doesn't exist, but it's used in the responseView

i'm doing the same in my add-on, but it's IMHO a strange way^^.
Is there any way to return this without an pseudo view?
PHP:
        else {
            return $this->responseView('Ragtek_Invite_ViewAdmin_Index', 'foo', $user);
        }
        return $this->responseView('Ragtek_Invite_ViewAdmin_Index', 'foo', $params);
 

Robbo

Well-known member
#2
I would say it is there in case a mod or something wants to test for that template, more as a reference thing. In listeners etc.
 

Mike

XenForo developer
Staff member
#3
The template can be used as a hint for the JSON output.

Or it is simply there if there is need for another view type which would output the template.