[TYPO3-50-general] How to get JSON View
Andreas Lappe
nd at off-pist.de
Wed Nov 4 13:10:29 CET 2009
On 4.11.09, Karsten Dambekalns wrote:
> On 30.10.09 09:36, Andreas Lappe wrote:
> > I had hoped to use my existing showAction (for html) to output the JSON,
> > but with $this->view->assign('lala', $lala) I cannot use $lala in view.
> > Is there another special/magic way to do this?
> I think I don't really get your problem. Could you post some code to
> look at?
It might all be a conceptional problem on my side. What I have in my
controller:
/**
* Show detail
*
* @param \F3\Proyectito\Domain\Model\Todolist $todolist
* @return string view
*/
public function showAction(\F3\Proyectito\Domain\Model\Todolist $todolist) {
$this->view->assign('todolist', $todolist);
$this->view->assign('todos', $this->todoRepository->findByTodolist($todolist));
}
which works fine for the standard html/fluid view. But as I cannot use
fluid to access `todolist´ in my json-view, I have to write it like
this:
/**
* Show detail
*
* @param \F3\Proyectito\Domain\Model\Todolist $todolist
* @return string view
*/
public function showAction(\F3\Proyectito\Domain\Model\Todolist $todolist) {
$this->view->todolist = $todolist;
$this->view->todos = $this->todoRepository->findByTodolist($todolist);
}
I can now access the two properties from within my view and output as
json. And of course I can combine these two ways to get both, but then I
wonder if that's really the way to go...
In TYPO3CR you used a separate controller for the json-service, so you
used the second approach. What's the way to go?
I hope it's more clear this time
Andy
--
``If you don't know anything about computers, just remember that they
are machines that do exactly what you tell them but often surprise you
in the result.´´ [Richard Dawkins, The Blind Watchmaker]
More information about the TYPO3-project-5_0-general
mailing list