Two things to note in general:

- you do not need to use & or setAttributeByRef(). PHP does copy on  
change, not copy on assign :)
- use json_encode(), it's much more reliable especially when it comes  
to escaping stuff!

Now, the implementational details aside:

Your Action should never, ever, be concerned with what the output type  
is!

Also, the proper way to do this is:

- have an output type "json" or "jsonhtml"
- set up a layout with a content layer
- use the same template rules there, so it just uses the html templates
- ... and a decorator layer where you do echo  
json_encode(array('place' => $template['place'], 'html' => $inner));

Hope that helps,

David

P.S: you do not have to change $template everywhere - you can change  
the name of that variable to $t or so. Are you aware of that? You  
could also configure it so that it's extracted to $html, $place etc,  
but that's not really recommended.


Am 11.02.2008 um 19:42 schrieb Liutauras:

> Hi all,
>
> i searching for the best solution of Ajax, JSON, HTML combination.
> Now my solution looks like:
> View::
>    executeHtml
>    executeJson
>
> templates
>    IndexSuccess
>    Json.IndexSuccess
>
> --------------------------
> When app receives Ajax request he will output Json template. Json
> template looks like that:
> ....
> '"place":"' . $template['place'] . '",' .
> '"html":' . json_encode( $template['html'] ) . ',' .
> ....
> And there i got this solution after Ajax request:
> Action::executeRead()
> // this executes when output type is 'json'
> // selfaction/module is because many of actions will be called with  
> ajax.
> executes ...->createExecutionContainer(SelfModule, SelfAction,  
> 'xhtml');
> $html = &$cntnr->execute()->getContent();
> $this->setAttribute('place', 'main_content');
> $this->setAttributeByRef('html', $html );
>
> And Vualia i got Json output with self Html in it.
> So is this best/good/notbad/bad solution?
>
> Thanx!
>
>
>
>
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.agavi.org/mailman/listinfo/users
>


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

Reply via email to