cfu479
cfu479

Reputation: 1

TYPO3: Passing argument from view to controller - argument type for parameter could not be detected

I'm trying to pass an argument from view to controller in TYPO3 8.7, but keep getting an error:

#1253175643: The argument type for parameter $player of method Playground\Tabletennis\Controller\AdminController->playerdetailsAction() could not be detected.

A list of players is passed from the controller to the view. There I pass the list trough to a partial, in which I use a for each loop (as player) to display the names, surrounded by a link.action which should take the player over to the controller again.

I get the list of players from the queryBuilder and contains uid and name. Iterating trough them works. But when I click on a name I get an error. The link 'more information' says, I have to fetch the argument manually, but trying $keyword = $this->request->getArgument('player'); didn't work either.

AdminController.php:

/**
* action info
*
*/
public function infoAction()
{
    $players = $this->getPlayers();

    $this->view->assign('players', $players);
}

/**
* action playerdetails
*
*/
public function playerdetailsAction($player)
{
   $this->view->assign('player', $player);
}

/**
* action returnPlayers
*/
function getPlayers()
{
    $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tabletennis_domain_model_players');
    $statement = $queryBuilder
      ->select('uid', 'name')
      ->from('tx_tabletennis_domain_model_players')
      ->addOrderBy('name', 'ASC')
      ->execute();
    while ($row = $statement->fetchAll()) {
    return $row;
    }
}

view:


Players:
<br /><br />

<ol>

<f:for each="{players}" as="player">

    <li>
        <f:link.action action="playerdetails" arguments="{player:player}">
           <b>{player.name}</b>
        </f:link.action>
    </li>


</f:for>

</ol>

What I need is the uid of the selected player passed to the controller, but don't know how.

Upvotes: 0

Views: 1629

Answers (2)

cfu479
cfu479

Reputation: 1

Ok, so something went wrong when handing arguments from controller to template to partial and then back to the controller. I removed the partial and packed the code into the template. From there the argument is passed and I can grab the argument with "$this->request->getArgument('player')".

Still don't exactly know what I did wrong, but it works this way.

Upvotes: 0

Rudy Gnodde
Rudy Gnodde

Reputation: 4575

You need to set which type a parameter is in the annotation of the function (and/or if it's an Object as a type hint. If you don't do that, the system won't know what to make of the uid it gets through the GET variable. In your case this would make it something like:

/**
 * action playerdetails
 *
 * @param \MyVendor\MyExt\Domain\Model\Player $player
 */
public function playerdetailsAction(\MyVendor\MyExt\Domain\Model\Player $player)
{
    $this->view->assign('player', $player);
}

After you change this, you do most likely need to clear the cache in the Install Tool before it will work.

More on this you can find here: https://docs.typo3.org/typo3cms/ExtbaseFluidBook/7-Controllers/1-Creating-Controllers-and-Actions.html#flow-pattern-display-a-single-domain-object

Upvotes: 3

Related Questions