Cannot assign string to property of type int

MKI-Miro
Člen | 261
+
0
-

Ahojte

Vo formulari mam

$form->addHidden('author_id');

Pricom trieda Blog ma

public int $author_id;

A presenter:

$data = $form->getValues(Blog::class);
$this->blogRepository->add($data);

Preco to neviem premapovat na int? pripadne nemohlo by existovat addHiddenInteger?

Dakujem

Keeehi
Člen | 36
+
+2
-

Mělo by stačit jen tomu inputu přidat pravidlo, ne?

->addRule(Form::INTEGER)
MKI-Miro
Člen | 261
+
0
-

dakujem funguje, problem mame ale este ak je ID – primany kluc

Ak sa robi edit tak vsetko funguje spravne lebo ID je vyplnene.

Ak sa robi insert (id je prazdne) tak dostanem error Cannot assign string to property App\Model\ProductLanguage::$id of type int

Ako toto vyriesit?

dakujem

NouF
Backer | 65
+
0
-

MKI-Miro napsal(a):

dakujem funguje, problem mame ale este ak je ID – primany kluc

Ak sa robi edit tak vsetko funguje spravne lebo ID je vyplnene.

Ak sa robi insert (id je prazdne) tak dostanem error Cannot assign string to property App\Model\ProductLanguage::$id of type int

Ako toto vyriesit?

dakujem

Ukaz tu funkci

Editoval NouF (25. 5. 2021 22:27)

MKI-Miro
Člen | 261
+
0
-
public function productLanguageFormSubmitted(Form $form, array $values): void
    {
        $data = $form->getValues(ProductLanguage::class);

        if (isset($data->id) && !empty($data->id)) {
            $item = $this->productLanguageRepository->findAll()->get($data->id);
            $item->update($values);
        } else {
            $this->productLanguageRepository->add($data, $this->languageId);
        }
    }