Question

In the following code booksis a list of book object containing certain properties. And by clicking on the title, it goes to an action display

Fluid template is

 <f:for each="books" as="book">
    <f:link.action action="display" arguments="{book: book}"> {book.title} </f:link.action>
 </f:for>

In controller

public function displayAction(){
    print_r($this->request->getArguments());
}

The value of book here is not being set. [book] => null. I try printing the class of it, it still gives me null.

It works fine when I send the arguments as book.title instead of the entire object

What am I missing here? Is this the right way to pass objects as arguments ?

EDIT:

Initially I tried this way.

public function displayAction(\TYPO3\MyExt\Domain\Model\Book $book) {}

But this gives me

Exception while property mapping at property path "":No converter found which can be used to convert from "string" to "TYPO3\MyExt\Domain\Model\Book"

The class Book is something which I created manually and is not registered under extension builder.

Was it helpful?

Solution

You could try it with a parameter for the action:

     public function myAction(Tx_MyExt_Domain_Model_Book $book) {
        $this->view->assignMultiple(array(
           'title' => $book->getTitle(),
           'label' => $book->getLabel(),
           'content' => $book->getContent()
        ));
     }

EDIT: I updated the example.

Update:

It works with book.title because it's just a string. When you want a complete book object it needs to be found in some storage. A database e.g.. Hence that means you need a model and a repository. Also an entry in the tca and the tables files. Better create your Models with the extension builder, it's much easier and safer for the beginning.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top