Symfony EntityType
I try to get from my Form EntityType.
which will get from the entity the name and the ID.
->add('supplier', EntityType::class, [
'class' => AppEntitySupplier::class,
'choice_value' => 'id',
'choice_label' => 'name',
])
i'm getting results as expected.
<select id="expense_supplier" name="expense[supplier]" class="form-control">
<option value="1">PayPal</option>
<option value="2">FB</option>
<option value="3">Yotube</option>
</select>
And he's getting the Value AS integer. as the entity requirement,
but when i Submit the form. i'm getting the error:
Expected argument of type "integer", "AppEntitySupplier" given.
My Supplier Entity:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
*/
class Supplier
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=50)
*/
private $name;
/**
* @ORMColumn(type="string", length=50)
*/
private $tax_id;
/**
* @ORMColumn(type="integer", length=25)
*/
private $category;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getTaxId(): ?string
{
return $this->tax_id;
}
public function setTaxId(string $tax_id): self
{
$this->tax_id = $tax_id;
return $this;
}
public function getCategory(): ?int
{
return $this->category;
}
public function setCategory(int $category): self
{
$this->category = $category;
return $this;
}
}
My Contoller:
/**
* @Route("/expense/add", name="expense_add")
*/
public function add(Request $request): Response
{
$form = $this->createForm(AppFormExpenseType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($form->getData());
$em->flush();
return $this->redirectToRoute('expense_list');
}
return $this->render('Admin/SuppliersTemplate.html.twig', [
'display' => 'form',
'title' => 'add.expense',
'form' => $form->createView()
]);
}
I try a lot of ways, but nothing helps,
Using Symfony 4.1
Thanks
symfony symfony4
|
show 2 more comments
I try to get from my Form EntityType.
which will get from the entity the name and the ID.
->add('supplier', EntityType::class, [
'class' => AppEntitySupplier::class,
'choice_value' => 'id',
'choice_label' => 'name',
])
i'm getting results as expected.
<select id="expense_supplier" name="expense[supplier]" class="form-control">
<option value="1">PayPal</option>
<option value="2">FB</option>
<option value="3">Yotube</option>
</select>
And he's getting the Value AS integer. as the entity requirement,
but when i Submit the form. i'm getting the error:
Expected argument of type "integer", "AppEntitySupplier" given.
My Supplier Entity:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
*/
class Supplier
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=50)
*/
private $name;
/**
* @ORMColumn(type="string", length=50)
*/
private $tax_id;
/**
* @ORMColumn(type="integer", length=25)
*/
private $category;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getTaxId(): ?string
{
return $this->tax_id;
}
public function setTaxId(string $tax_id): self
{
$this->tax_id = $tax_id;
return $this;
}
public function getCategory(): ?int
{
return $this->category;
}
public function setCategory(int $category): self
{
$this->category = $category;
return $this;
}
}
My Contoller:
/**
* @Route("/expense/add", name="expense_add")
*/
public function add(Request $request): Response
{
$form = $this->createForm(AppFormExpenseType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($form->getData());
$em->flush();
return $this->redirectToRoute('expense_list');
}
return $this->render('Admin/SuppliersTemplate.html.twig', [
'display' => 'form',
'title' => 'add.expense',
'form' => $form->createView()
]);
}
I try a lot of ways, but nothing helps,
Using Symfony 4.1
Thanks
symfony symfony4
Can you post your entity class file?
– Rodmar Zavala
Nov 21 '18 at 23:21
yes, i update the post.
– kalites
Nov 21 '18 at 23:30
3
So somewhere in your code you are trying to validate that supplier is an integer? When you use an EntityType you actually end up with a Supplier object. The type class takes care of converting the form value to an actual object. Maybe show where the error is coming from.
– Cerad
Nov 21 '18 at 23:33
Share the controller method in which this form is getting submitted
– Trix
Nov 22 '18 at 4:09
1. when i change this Type to IntType it's working, and i need it as Select Option, and the form submit without any issue
– kalites
Nov 22 '18 at 17:10
|
show 2 more comments
I try to get from my Form EntityType.
which will get from the entity the name and the ID.
->add('supplier', EntityType::class, [
'class' => AppEntitySupplier::class,
'choice_value' => 'id',
'choice_label' => 'name',
])
i'm getting results as expected.
<select id="expense_supplier" name="expense[supplier]" class="form-control">
<option value="1">PayPal</option>
<option value="2">FB</option>
<option value="3">Yotube</option>
</select>
And he's getting the Value AS integer. as the entity requirement,
but when i Submit the form. i'm getting the error:
Expected argument of type "integer", "AppEntitySupplier" given.
My Supplier Entity:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
*/
class Supplier
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=50)
*/
private $name;
/**
* @ORMColumn(type="string", length=50)
*/
private $tax_id;
/**
* @ORMColumn(type="integer", length=25)
*/
private $category;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getTaxId(): ?string
{
return $this->tax_id;
}
public function setTaxId(string $tax_id): self
{
$this->tax_id = $tax_id;
return $this;
}
public function getCategory(): ?int
{
return $this->category;
}
public function setCategory(int $category): self
{
$this->category = $category;
return $this;
}
}
My Contoller:
/**
* @Route("/expense/add", name="expense_add")
*/
public function add(Request $request): Response
{
$form = $this->createForm(AppFormExpenseType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($form->getData());
$em->flush();
return $this->redirectToRoute('expense_list');
}
return $this->render('Admin/SuppliersTemplate.html.twig', [
'display' => 'form',
'title' => 'add.expense',
'form' => $form->createView()
]);
}
I try a lot of ways, but nothing helps,
Using Symfony 4.1
Thanks
symfony symfony4
I try to get from my Form EntityType.
which will get from the entity the name and the ID.
->add('supplier', EntityType::class, [
'class' => AppEntitySupplier::class,
'choice_value' => 'id',
'choice_label' => 'name',
])
i'm getting results as expected.
<select id="expense_supplier" name="expense[supplier]" class="form-control">
<option value="1">PayPal</option>
<option value="2">FB</option>
<option value="3">Yotube</option>
</select>
And he's getting the Value AS integer. as the entity requirement,
but when i Submit the form. i'm getting the error:
Expected argument of type "integer", "AppEntitySupplier" given.
My Supplier Entity:
<?php
namespace AppEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
*/
class Supplier
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=50)
*/
private $name;
/**
* @ORMColumn(type="string", length=50)
*/
private $tax_id;
/**
* @ORMColumn(type="integer", length=25)
*/
private $category;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getTaxId(): ?string
{
return $this->tax_id;
}
public function setTaxId(string $tax_id): self
{
$this->tax_id = $tax_id;
return $this;
}
public function getCategory(): ?int
{
return $this->category;
}
public function setCategory(int $category): self
{
$this->category = $category;
return $this;
}
}
My Contoller:
/**
* @Route("/expense/add", name="expense_add")
*/
public function add(Request $request): Response
{
$form = $this->createForm(AppFormExpenseType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($form->getData());
$em->flush();
return $this->redirectToRoute('expense_list');
}
return $this->render('Admin/SuppliersTemplate.html.twig', [
'display' => 'form',
'title' => 'add.expense',
'form' => $form->createView()
]);
}
I try a lot of ways, but nothing helps,
Using Symfony 4.1
Thanks
symfony symfony4
symfony symfony4
edited Nov 22 '18 at 17:09
kalites
asked Nov 21 '18 at 22:50
kaliteskalites
3410
3410
Can you post your entity class file?
– Rodmar Zavala
Nov 21 '18 at 23:21
yes, i update the post.
– kalites
Nov 21 '18 at 23:30
3
So somewhere in your code you are trying to validate that supplier is an integer? When you use an EntityType you actually end up with a Supplier object. The type class takes care of converting the form value to an actual object. Maybe show where the error is coming from.
– Cerad
Nov 21 '18 at 23:33
Share the controller method in which this form is getting submitted
– Trix
Nov 22 '18 at 4:09
1. when i change this Type to IntType it's working, and i need it as Select Option, and the form submit without any issue
– kalites
Nov 22 '18 at 17:10
|
show 2 more comments
Can you post your entity class file?
– Rodmar Zavala
Nov 21 '18 at 23:21
yes, i update the post.
– kalites
Nov 21 '18 at 23:30
3
So somewhere in your code you are trying to validate that supplier is an integer? When you use an EntityType you actually end up with a Supplier object. The type class takes care of converting the form value to an actual object. Maybe show where the error is coming from.
– Cerad
Nov 21 '18 at 23:33
Share the controller method in which this form is getting submitted
– Trix
Nov 22 '18 at 4:09
1. when i change this Type to IntType it's working, and i need it as Select Option, and the form submit without any issue
– kalites
Nov 22 '18 at 17:10
Can you post your entity class file?
– Rodmar Zavala
Nov 21 '18 at 23:21
Can you post your entity class file?
– Rodmar Zavala
Nov 21 '18 at 23:21
yes, i update the post.
– kalites
Nov 21 '18 at 23:30
yes, i update the post.
– kalites
Nov 21 '18 at 23:30
3
3
So somewhere in your code you are trying to validate that supplier is an integer? When you use an EntityType you actually end up with a Supplier object. The type class takes care of converting the form value to an actual object. Maybe show where the error is coming from.
– Cerad
Nov 21 '18 at 23:33
So somewhere in your code you are trying to validate that supplier is an integer? When you use an EntityType you actually end up with a Supplier object. The type class takes care of converting the form value to an actual object. Maybe show where the error is coming from.
– Cerad
Nov 21 '18 at 23:33
Share the controller method in which this form is getting submitted
– Trix
Nov 22 '18 at 4:09
Share the controller method in which this form is getting submitted
– Trix
Nov 22 '18 at 4:09
1. when i change this Type to IntType it's working, and i need it as Select Option, and the form submit without any issue
– kalites
Nov 22 '18 at 17:10
1. when i change this Type to IntType it's working, and i need it as Select Option, and the form submit without any issue
– kalites
Nov 22 '18 at 17:10
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421540%2fsymfony-entitytype%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421540%2fsymfony-entitytype%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post your entity class file?
– Rodmar Zavala
Nov 21 '18 at 23:21
yes, i update the post.
– kalites
Nov 21 '18 at 23:30
3
So somewhere in your code you are trying to validate that supplier is an integer? When you use an EntityType you actually end up with a Supplier object. The type class takes care of converting the form value to an actual object. Maybe show where the error is coming from.
– Cerad
Nov 21 '18 at 23:33
Share the controller method in which this form is getting submitted
– Trix
Nov 22 '18 at 4:09
1. when i change this Type to IntType it's working, and i need it as Select Option, and the form submit without any issue
– kalites
Nov 22 '18 at 17:10