I'm new to symfony I have a web controller , In Web controller i get all user's name from UserRepository where roll is not Admin. every thing fine with createAction but when i try to update web data in editAction i get an error like
The value of type "object" cannot be converted to a valid array key.
In createAction im getting users
$all_users = $em->getRepository('MWANMOBILEBIBundle:User')->allWebUser();
// var_dump($all_users);
$user_arr=array();
foreach ($all_users as $single_user){
$user_arr[$single_user['id']]=$single_user['username'];
}
$form = $this->createFormBuilder()
->add('description', 'text')
->add('primaryUrl', 'text')
->add('testUrl', 'text')
->add('notes', 'textarea')
->add('save', 'submit', array('label' => 'Create Web Service'))
->add('user', 'choice', array('choices' => $user_arr ))
->add('parent', 'choice', array('choices' => $user_service,'required' => false,))
->add('serverStatus', 'checkbox')
->add('statusEmail' ,'email')
->add('statusMessage' , 'textarea')
->getForm();
In createFormBuilder below mentioned line is working fine
->add('user', 'choice', array('choices' => $user_arr ))
But when I'm using in edit action i got an error
The value of type "object" cannot be converted to a valid array key.
here is my editAction code
$em = $this->getDoctrine()->getManager();
$web = $em->getRepository('MWANMOBILEBIBundle:Web')->find($id);
$all_users = $em->getRepository('MWANMOBILEBIBundle:User')->allWebUser();
var_dump($all_users);
$user_arr=array();
foreach ($all_users as $single_user)
{
$user_arr[$single_user['id']]=$single_user['username'];
}
$form = $this->createFormBuilder($web)
->add('description', 'text')
->add('primaryUrl', 'text')
->add('testUrl', 'text')
->add('notes', 'textarea')
->add('user', 'choice', array('choices' => $user_arr ))
//->add('user', 'entity', array('class' => 'MWANMOBILEBIBundle:User',
// 'property' => 'username',))
->add('parent', 'entity', array('class' => 'MWANMOBILEBIBundle:Service',
'property' => 'description' ))
->add('serverStatus', 'checkbox')
->add('statusEmail' ,'email')
->add('statusMessage' , 'textarea')
->add('save', 'submit', array('label' => 'Update Web Service'))
->getForm();