H
H
hiimnotwordy2019-02-13 19:31:50
symfony
hiimnotwordy, 2019-02-13 19:31:50

Not sure how to work with emoji in symfony?

If I specify the field type type="string" in Entity, and manually set the field type to varbinary in the database, then emoji are saved and everything works.

/**
     * @ORM\Column(type="string", length=120, nullable=true)
     */
    private $freeName;

    /**
     * @return string
     */
    public function getFreeName(): ?string
    {
        return $this->freeName;
    }

    /**
     * @param string $freeName
     */
    public function setFreeName($freeName): self
    {
        $this->freeName = $freeName;

        return $this;
    }

But after such an intervention, it is impossible to update the database
php bin/console doctrine:schema:update --force
If I initially set the field type to binary
* @ORM\Column(type="binary", length=120, nullable=true)

that I receive not a line, and a resource. How to deal with the field, with getters and setters, in order to save emoji in the database in a competent way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2019-02-13
@hiimnotwordy

Use the utf8mb4 encoding, additionally you need to specify the parameters for the entity / table and connection.
More or less like this:

/**
 * @ORM\Entity
 * @ORM\Table(options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"})
 */

# app/config/config.yml
doctrine:
    dbal:
        charset:  utf8mb4

https://github.com/symfony/symfony-docs/issues/5526
jameshalsall.co.uk/posts/4-byte-utf-8-characters-w...
https://avris.it/blog/emojis -in-doctrine

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question