-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
3.1 - Jsonview auto serialize #6502
Conversation
* views to provide layout-like functionality. | ||
* If you need the regular view template processing you can set `_serialize` to | ||
* false which will turn off automatic serialization and instead view template | ||
* and layotu will be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick typo in layout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a nitpick, this ends up in API docs :)
lgtm |
Shouldnt XmlView behave similar? |
XmlView should behave in a similar way. Having them be different will be not good. Also this change could be interpreted as an API breaking change. If an app was relying on using view files, it would now default to serializing which could be unexpected. What was wrong with the |
It would still require adding |
Doing so will serialize all available view variables.
Set '_serialize' to false to turn off serialization.
5a27b48
to
9893894
Compare
* When the view is rendered, the `$posts` view variable will be serialized | ||
* into JSON. | ||
* By default all view variables will be serialized to JSON. So for above example | ||
* the `$posts` view variable will be serialized into JSON. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is.
Seems like an API break, and perhaps a serious one for certain users. As such, I'm 👎 . Do we want to move to breaking the API in minor releases? |
Would a controller property work? So, setting serialize in your AppController to true would auto-serialize the json view? And it'd default to false? Right now all my json stuff has that serialize view property which is cumbersome. |
@patrickconroy You can set So that's what we should do here IMO. |
I'll switch back to not serializing by default to avoid BC issues. Instead can document the fact that one can set |
This sounds like a much safer plan. We could even make this part of the AppController in the project skeleton. |
Done. |
This would probably have fit into 3.0 now as well. But with 3.1 it can be communicated better. |
No it won't as this change causes this test to fail. |
Doesn't make much sense, as you said :) But all right, 3.1 is fine. |
It contains common code used by view which return serialized data.
|
} | ||
parent::loadHelpers(); | ||
} | ||
public $_responseType = 'xml'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why underscore public attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mistake in all 3 classes. Should be protected.
$response->type('json'); | ||
} | ||
} | ||
public $_responseType = 'json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
Looks good to me. This looks far safer than the original approach. |
3.1 - Add support for `_serialize` = `true` for JsonView and XmlView
Hey guys. With the way
If you do the above right now, you get this response, which isn't valid JSON:
However, if you have more than one var, it works as expected:
Returns:
The unexpectedness of that makes me think this is a bug, but it's possible that's as intended. |
@patrickconroy Could you open a new issue with that? |
Sure np. |
Thanks. |
Refs #6500