PHP code example of kucharovic / money-bundle

1. Go to this page and download the library: Download kucharovic/money-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kucharovic / money-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...

            new JK\MoneyBundle\JKMoneyBundle(),
        ];

        // ...
    }

    // ...
}

// src/AppBundle/Entity/Proudct.php

use Doctrine\ORM\Mapping as ORM;
use Money\Money;

// ...
class Product
{
    // ...

    /**
     * @var Money
     *
     * @ORM\Embedded(class="Money\Money")
     */
    private $price;

    // ...

    public function __construct()
    {
        $this->price = Money::CZK(0);
    }

    public function setPrice(Money $price): void
    {
        $this->price = $price;
    }

    public function getPrice(): Money
    {
        return $this->price;
    }

// src/AppBundle/Entity/Proudct.php

// ...
use JK\MoneyBundle\Form\Type\MoneyType;

class ProductType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('price', MoneyType::class)
        ;
    }
html
<!-- 1 599,90 Kč -->
Formated with czech locale {{ product.price|money }}<br>
<!-- 1599,9 -->
You can also specify scale, grouping and hide currency symbol {{ product.price|money(1, false, false) }