On 14.02.2009, at 15:56, Michal Charemza wrote:

For the errors of the form, I think I agree. However, if there are no
errors, I would like to return the whole comment as HTML to be
injected into the page. If HTML isn't returned within the JSON, then
the front-end javascript would have to know about the html-structure
of the comments (which I would prefer to avoid). So the executeJson()
method would need to access both a template for JSON, and the template
used for comments. How would I go about do this? I'm guessing it's
something to do with layers, but unfortunately I've not got to grips
with quite how layers work yet...

That's pretty easy :) It works like this:

- if an error occurs, your AddCommentErrorView (or whatever it's called) is run, and the respective execute() method for the output type is called. Mind you that you should *always* have an "Error" view in addition to the "Input" view, even if the "Error" view then re-uses the "Input" template for normal HTML pages. This situation should make it pretty obvious why that is a good idea :)
- if no error occurs, your AddCommentSuccessView is called. It will
 - redirect (!) to the blog post for HTML pages
 - ???? for Ajax requests

So, there's our problem. Simple solution: you *forward* (not redirect) internally to the ViewComment action, and change the output type. Also, you force the request method to "read", just because it feels better:

return $this->createForwardContainer('Module', 'ViewComment', array('id' => $commentId), 'html', 'read');

Of course, you now need to load a different layout in your ViewCommentSuccessView in this case. One solution would be to simply check if the execution was due to a forward:

if($this->getContainer()->getParameter('is_forward')) { $layoutName = 'simple'; }

Hope that helps,

- David

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users

Reply via email to