I have a form from which i am fetching the data as array in controller from $request->get() method and want to submit that data to database..
This is the array i am getting when i print the post variable:
Array
(
[country] => Array
(
[0] => 24
[1] => 4
)
[state] => Array
(
[0] => Cuando Cubango
[1] => Badakhshan
)
[activity] => Array
(
[0] => 3
[1] => 5
)
[activity_0] => Array
(
[0] => 3
)
)
I want them to insert in database in this format:
country state activity
24 Cuando Cubango 3
24 Cuando Cubango 5
4 Badakhshan 3
What i have tried so far is this:
$active = $request->get('activity');
if (!empty($active)) {
foreach ($active as $activity) {
$states = $request->get('state');
$c = $request->get('country');
$Bidactivity = $active;
foreach ($states as $state) {
foreach ($Bidactivity as $orgact) {
$activity_to_db = new Activity();
$activity_to_db->setActivityid($active);
$activity_to_db->setState($states);
$activity_to_db->setBidOrganiser($organiserDetails);
$activity_to_db->setCountry($c);
$em->persist($activity_to_db);
$em->flush();
}
}
}
}
But i am getting the array to string conversion error. Please guide.
setCountrytakes array as a parameter ? if not then you are passing country array$cto a function which needs a single value not array thats why you are getting this error its a guess because you have not posted definition ofActivity