3

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.

2
  • What is the output of: ` <f:for each="books" as="book"> <f:debug>{book}</f:debug> <f:link.action action="display" arguments="{book: book}"> {book.title} </f:link.action> </f:for>` ? Commented Jun 26, 2013 at 14:59
  • It gives me a book prototype object with all its properties! And the book in turn contains other objects like date object which has properties like day and month. To put it simple its an object of Book Commented Jun 27, 2013 at 5:16

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Okay! But what if I want to pass objects (regardless of domain models) as parameters ? That's not a possibility?
PHP is stateless. That means if you create an object in your script (which is executed on the server) and pass it into your view it gets encrypted and the key is send to the client (the browser) and written into some attribute of a html tag. Your object is lost then. When clicking a link that calls an action, extbase can restore it e.g. from the database using the key. You can of course also store it somehow in a cookie. Where a domain model would not be necessary. But that would probabely not be easier.
You're welcome. Relating to the uff: It's not that hard :) When using the f:link.action viewhelper for example, and passing an object, extbase writes url parameter at the href attribute of an anchor tag. This is what I meant by key. It's the controller, the action and the id to find the object in the database. The repository is handling the request to the database. So you actually do not need to do anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.