Get view runtime values from within a Controller

I create my view runtime values with View.share() in my middleware. I would like to access them in controllers. How (if) can I do this?

I doubt it’s possible…
What’s the use-case you have?

Hey @McSneaky. Well, based on the fact that the values are shared with views I thought it would be logical to be able to have an assess to them via controllers or the like.

If this is not possible with shared values then is this possible with view globals?

My use cases are basic - share currently set locale, some user data, route names etc. like these.

Hmm, now when I think about it… You should be able to do it. Not entirely sure how tho.

Most likely if you take log out view in the http context you could find something in there
Something like this:

// Total pseudocode
// In controller method
async index ({ view }) {
  console.log(view.globals) // Or view.something_else
1 Like

Yes. I rememeber I tried to print out the view object. There are as well View.share()'d values under somewhat local member in there.

But I thought the officially documented way to get these would be better, not a workaround. So I resorted to get the values I needed directly from their sources instead of getting the values copies from the view.

1 Like