Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/LiveComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2728,18 +2728,18 @@ You can also pass extra (scalar) data to the listeners::
// ...

$this->emit('productAdded', [
'product' => $product->getId(),
'productId' => $product->getId(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will make the Product entity example (L2745-2752) not working :|

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you keep the "product" var name and fix the $data[...] you spotted ? :)

]);
}

In your listeners, you can access this by adding a matching argument
name with ``#[LiveArg]`` in front::

#[LiveListener('productAdded')]
public function incrementProductCount(#[LiveArg] int $product)
public function incrementProductCount(#[LiveArg] int $productId)
{
$this->productCount++;
$this->lastProduct = $data['product'];
$this->lastProductId = $productId;
}

And because event listeners are also actions, you can type-hint an argument
Expand Down