Form Symfony e problema array

Linguaggi di programmazione: php, perl, python, C, bash e tutti gli altri.
enigma83
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1400
Iscrizione: mercoledì 2 gennaio 2008, 13:12

Form Symfony e problema array

Messaggio da enigma83 »

come da titolo ho un problema di conversione array to string nel controller di symfony posto l'action:

Codice: Seleziona tutto

	public function createAction(Request $request)
	{
	        $nutrizionista = new Nutrizionisti();
        	$form = $this->createFormBuilder($nutrizionista)
    		->add('idRuoli', 'integer')
    		->add('RagioneSociale', 'text')
    		->add('Cognome', 'text')
    		->add('Nome', 'text')
    		->add('Indirizzo', 'text')
    		->add('CAP', 'integer')
    		->add('Localita', 'text')
    		->add('Telefono', 'text')
    		->add('Cellulare', 'text')
    		->add('Mail', 'text')
    		->add('Facebook', 'text')
    		->add('Linkedin', 'text')
    		->add('Google', 'text')
    		->add('CodiceFiscale', 'text')
    		->add('PartitaIva', 'text')
    		->add('OrdineIscrizione', 'text')
    		->add('NumeroIscrizione', 'text')
    		->add('CittaIscrizione', 'text')
    		->add('Logo', 'text')
    		->add('Utente', 'text')
    		->add('Password', 'text')
    		->add('Active', 'integer')
    		->add('Note', 'textarea')                    	
		->add('save', 'submit', array('label' => 'Inserisci Nutrizionista'))
                ->getForm();
 
        	$form->handleRequest($request);
 
        	if ($form->isValid()) {
            		$em = $this->getDoctrine()->getManager();
            		$em->persist($nutrizionista);
            		$em->flush();
 
            		return $this->redirect($this->generateUrl('/nutrizionisti'));
        	}
 
        	return $this->render(
            		array(
                		'form' => $form->createView()
            		)
        	);


    		$em->persist($nutrizionista);
    		$em->flush();
    	}
L'errore è questo:

Notice: Array to string conversion

Codice: Seleziona tutto

Stack Trace
in vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php at line 126   -
        }
        try {
            return $this->environment->loadTemplate((string) $name);
        } catch (\Twig_Error_Loader $e) {
            throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
        }
Avatar utente
Zoff
Moderatore Globale
Moderatore Globale
Messaggi: 33338
Iscrizione: mercoledì 10 ottobre 2007, 22:36

Re: Form Symfony e problema array

Messaggio da Zoff »

Devi riportare l'errore completo altrimenti non si capisce dov'è.

Comunque hai sicuramente assegnato ad una variabile che viene convertita in stringa un array.
Tirando a indovinare, è possibile che tu abbia inizializzato uno dei campi di classe di Nutrizionista ad array per sbaglio?

Qualcosa del tipo:

Codice: Seleziona tutto

class Nutrizionista {
    ...
    private $campo = array();
    ...
}
oppure:

Codice: Seleziona tutto

class Nutrizionista {
    ...
    public __constructor(){
        $this->campo = array();
    }
    ...
}
Prima di aprire una discussione leggi le Guide, poi vedi se c'è un HowTo nel Wiki e fai una ricerca nel Forum!
Applica semplicemente il [Risolto]! Prova: http://forum.ubuntu-it.org/viewtopic.php?f=70&t=548821
Vuoi qualcosa di piu' dal forum? Prova i miei script: http://forum.ubuntu-it.org/viewtopic.php?f=70&t=597066
enigma83
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1400
Iscrizione: mercoledì 2 gennaio 2008, 13:12

Re: Form Symfony e problema array

Messaggio da enigma83 »

Codice: Seleziona tutto

Notice: Array to string conversion
500 Internal Server Error - ContextErrorException

Codice: Seleziona tutto

Stack Trace
in vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php at line 126   -
        }
        try {
            return $this->environment->loadTemplate((string) $name);
        } catch (\Twig_Error_Loader $e) {
            throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
        }
at ErrorHandler ->handleError ('8', 'Array to string conversion', '/var/www/dietsolution/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php', '126', array('name' => array('form' => object(FormView)))) 
in vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php at line 126   + 
at TwigEngine ->load (array('form' => object(FormView))) 
in vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php at line 50   + 
at TwigEngine ->render (array('form' => object(FormView)), array()) 
in vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/TwigEngine.php at line 72   + 
at TwigEngine ->render (array('form' => object(FormView)), array()) 
in vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/TwigEngine.php at line 97   + 
at TwigEngine ->renderResponse (array('form' => object(FormView)), array(), null) 
in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 176   + 
at Controller ->render (array('form' => object(FormView))) 
in src/Diet/NutrizionistiBundle/Controller/DefaultController.php at line 73   + 
at DefaultController ->createAction (object(Request)) 
at call_user_func_array (array(object(DefaultController), 'createAction'), array(object(Request))) 
in app/bootstrap.php.cache at line 3094   + 
at HttpKernel ->handleRaw (object(Request), '1') 
in app/bootstrap.php.cache at line 3056   + 
at HttpKernel ->handle (object(Request), '1', true) 
in app/bootstrap.php.cache at line 3207   + 
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
in app/bootstrap.php.cache at line 2429   + 
at Kernel ->handle (object(Request)) 
in web/app_dev.php at line 28   + 
at require ('/var/www/dietsolution/web/app_dev.php') 
in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php at line 36   + 
Logs   - 1 error
INFO - Matched route "diet_nutrizionisti_create". 
INFO - Populated the TokenStorage with an anonymous Token. 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". 
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Notice: Array to string conversion" at /var/www/dietsolution/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 126 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". 
Stack Trace (Plain Text)   +
Va bene cosi :( ?
enigma83
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1400
Iscrizione: mercoledì 2 gennaio 2008, 13:12

Re: Form Symfony e problema array

Messaggio da enigma83 »

Codice: Seleziona tutto

<?php

namespace Diet\NutrizionistiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Diet\NutrizionistiBundle\Entity\Nutrizionisti;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;


class DefaultController extends Controller
{
	public function indexAction()
	{
		$nutrizionista = $this->getDoctrine()
                ->getRepository('DietNutrizionistiBundle:Nutrizionisti')
                ->findAll();
 
		return $this->render(
			'DietNutrizionistiBundle:Default:index.html.twig',
			array(
			'Nutrizionisti' => $nutrizionista
			)
		);
	}


	public function createAction(Request $request)
	{
	        $nutrizionista = new Nutrizionisti();
        	$form = $this->createFormBuilder($nutrizionista)
    		->add('idRuoli', 'integer')
    		->add('RagioneSociale', 'text')
    		->add('Cognome', 'text')
    		->add('Nome', 'text')
    		->add('Indirizzo', 'text')
    		->add('CAP', 'integer')
    		->add('Localita', 'text')
    		->add('Telefono', 'text')
    		->add('Cellulare', 'text')
    		->add('Mail', 'text')
    		->add('Facebook', 'text')
    		->add('Linkedin', 'text')
    		->add('Google', 'text')
    		->add('CodiceFiscale', 'text')
    		->add('PartitaIva', 'text')
    		->add('OrdineIscrizione', 'text')
    		->add('NumeroIscrizione', 'text')
    		->add('CittaIscrizione', 'text')
    		->add('Logo', 'text')
    		->add('Utente', 'text')
    		->add('Password', 'text')
    		->add('Active', 'integer')
    		->add('Note', 'textarea')                    	
		->add('save', 'submit', array('label' => 'Inserisci Nutrizionista'))
                ->getForm();
 
        	$form->handleRequest($request);
 
        	if ($form->isValid()) {
            		$em = $this->getDoctrine()->getManager();
            		$em->persist($nutrizionista);
            		$em->flush();
 
            		return $this->redirect($this->generateUrl('/nutrizionisti'));
        	}
 
        	return $this->render(
            		array(
                		'form' => $form->createView()
            		)
        	);


    		$em->persist($nutrizionista);
    		$em->flush();
    	}

	public function showAction($id)
	{
		$nutrizionista = $this->getDoctrine()
		->getRepository('DietNutrizionistiBundle:Nutrizionisti')
        	->find($id);

    		if (!$nutrizionista) {
        		throw $this->createNotFoundException(
        	    		'Nessun nutrizionista trovato per l\'id '.$id
       		 	);
    		}

        	return $this->render('DietNutrizionistiBundle:Default:nutrizionista.html.twig',  array('nutrizionista' => $nutrizionista, 'id' => $id));
    	}

	public function updateAction($id)
	{
		$em = $this->getDoctrine()->getManager();
    		$nutrizionista = $em->getRepository('DietNutrizionistiBundle:Nutrizionisti')->find($id);

    		if (!$nutrizionista) {
        		throw $this->createNotFoundException(
            			'Nessun nutrizionista trovato per l\'id '.$id
        		);
    		}

    		$nutrizionista->setNome('Alessandro');
    		$em->flush();

    		return $this->redirect($this->generateUrl('/nutrizionisti'));
	}

	public function deleteAction($id)
	{
		$em = $this->getDoctrine()->getManager();
    		$nutrizionista = $em->getRepository('DietNutrizionistiBundle:Nutrizionisti')->find($id);

    		if (!$nutrizionista) {
        		throw $this->createNotFoundException(
            			'Nessun nutrizionista trovato per l\'id '.$id
        		);
    		}

    		$em->remove($nutrizionista);
		$em->flush();

    		return $this->redirect($this->generateUrl('/nutrizionisti'));
	}

}
Scrivi risposta

Ritorna a “Programmazione”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 6 ospiti