PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 11, 2022

[FIXED] Argument 3 passed to Symfony\Component\Form\FormRenderer::searchAndRenderBlock() must be of the type array, string given, called in C:\Users\

 January 11, 2022     php, symfony, twig     No comments   

Issue

I'm working to customize my form. In SiteType.php I have for example the following code :

class SiteType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('nom', null, ["attr"=>["class"=>"form-control"]])
            ->add('grandeVilleProche', null,["attr"=>["class"=>"form-control"]])
            ->add('villeLaPlusProche', null, ["attr"=>["class"=>"form-control"]])
            ->add('exposition', ChoiceType::class, array(
                'choices' => array(
                    'N' => 'N',
                    'NE ' => 'NE',
                    'E ' => 'E',
                    'SE ' => 'SE',
                    'S ' => 'S',
                    'SW ' => 'SW',
                    'W ' => 'W',
                    'NW ' => 'NW',
                    'toutes ' => 'toutes',
                    
                    
                ),
                // 'choices_as_values' => true, 
                'multiple' => true, 
                'expanded' => true
               
                    ))
            ->add('altitudeAuxPiedsdesVoies', null, ["attr"=>["class"=>"form-control"]])
            ->add('dureeMarcheAproche', null, ["attr"=>["class"=>"form-control"]])
            ->add('profilMarcheApproche', ChoiceType::class,
            array(
                    'choices' => array(
                        'Non connue'=>'Non connue',
                        "en montée facile"=>"en montée facile",
                        "en montée"=>"en montée",
                        "en montée raide" => "en montée raide",
                        "en descente facile"=> "en descente facile",
                        "en descente"=>"en descente",
                        "en descente raide"=>"en descente raide",
                        "sur du plat"=>"sur du plat",
                        "en rappel"=>"en rappel",
                        "par tyrolienne"=>"par tyrolienne", 
                        "en bateau"=>"en bateau",
                        "en montée et descente"=>"en montée et descente", 
                        "en montée et descente facile"=>"en montée et descente facile", 
                        "en montée et descente raide"=>"en montée et descente raide",
                        "en descente et montée"=> "en descente et montée",
                        "en descente et montée facile"=>"en descente et montée facile",
                        "en descente et montée raide"=>"en descente et montée raide",
                        "en télésiège"=>"en télésiège", 
                        "par pont de singe"=>"par pont de singe",
                )))
            ->add('practicabilitePiedsdesVoies', ChoiceType::class,
            array(  
                    'mapped' => false,
                    'choices' => array(
                        'Non connu'=>'Non connu',
                        "confortable"=>"confortable",
                        "correct"=>"correct",
                        "accidenté" => "accidenté",
                        "dangereux"=> "dangereux",
                )))
            ->add('latitude', null, ["attr"=>["class"=>"form-control"]])
            ->add('longitude', null, ["attr"=>["class"=>"form-control"]])
            ->add('nombreFalaise', null, ["attr"=>["class"=>"form-control"]])
            ->add('hauteurMax', null, ["attr"=>["class"=>"form-control"]])
            ->add('typeEscalade', ChoiceType::class, array(
                'choices' => array(
                    'Bloc ' => 'Bloc',
                    'Voies d\'une longueur ' => 'Voies d\'une longueur',
                    'Voies de plusieurs longueurs' => 'Voies de plusieurs longueurs',
                    'Psychobloc ' => 'Psychobloc',
                    'Structure Artificielle d\'Escalade gratuite et libre d\'accès' => 'Structure Artificielle d\'Escalade gratuite et libre d\'accès',
                    ),
                // 'choices_as_values' => true, 
                'multiple' => true, 
                'expanded' => true
                    ))
        
                 
            ->add('typeEquipement', ChoiceType::class, array(
                'choices' => array(
                    'sportif' => 'sportif',
                    'engagé ' => 'engagé',
                    'terrain d\'aventure' => 'terrain d\'aventure',
                    'moulinette' => 'moulinette',
                ),
                // 'choices_as_values' => true, 
                'multiple' => true, 
                'expanded' => true
                    ))
...

And in my _form.htm.twig I have to following code :

<div class="container">
    {{ form_start(form, {'attr':{'novalidate':'novalidate'}}) }}
        {{ form_errors(form.exposition) }}
        {{ form_label(form.nom, null, {'label': 'Nom',
        'label_attr': {'class': 'labbel1'}
        }) }}
        {{ form_widget(form.nom, {'attr': {'class': 'nom'}}) }}
        {{ form_label(form.exposition, null, {'label': 'Exposition',
        'label_attr': {'class': 'labbel2'}
        }) }}
        {{ form_widget(form.exposition, {'attr': {'class': 'expo-checkbox'}}) }}
        {{ form_label(form.typeEscalade, 'Type d\'escalade', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.typeEscalade, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.altitudeAuxPiedsdesVoies, 'Altitude aux pieds des voies', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.altitudeAuxPiedsdesVoies, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.dureeMarcheAproche, 'durée marche d\'aproche', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.dureeMarcheAproche, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.profilMarcheApproche, 'profilMarcheApproche', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.profilMarcheApproche, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.practicabilitePiedsdesVoies, null, 'Practicabilité aux pieds des voies', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.practicabiitePiedsdesVoies, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.latitude, 'latitude', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.latitude, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.longitude, 'longitude', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.longitude, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.nombreFalaise, 'Nombre de falaise', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.nombreFalaise, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.hauteurMax, 'Hauteur Max', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.hauteurMax, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.typeEquipement, 'Type d\'équipement', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.typeEquipement, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.nombredeVoie, 'Nombre de voie', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.nombredeVoie, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.difficulte, 'difficulte', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.difficulte, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.difficulte2, 'difficulte2', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.difficulte2, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.siteInteressantpourGrimpeur, 'Site interessant pour grimpeur', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.siteInteressantpourGrimpeur, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.typeRocher, 'Type de rocher', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.typeRocher, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.profileFalaise, 'Profile de falaise', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.profileFalaise, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.typedePrise, 'Type de prise', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.typedePrise, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.restriction, 'restriction', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.restriction, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.infoSuplementaire, 'Info suplementaire', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.infoSuplementaire, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.siteInternet, 'Site internet', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.siteInternet, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.voieMythique, 'Voie mythique', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.voieMythique, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.nomprenompseudo, 'Nom prenom pseudo', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.nomprenompseudo, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.adresseMail, 'Adresse mail', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.adresseMail, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.meilleurperiode, 'Meilleur période', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.meilleurperiode, {'attr': {'class': 'expo-checkbox2'}}) }}
        {{ form_label(form.site, 'Photos', {'attr': {'class': 'labbel3'}}) }}
        {{ form_widget(form.site, {'attr': {'class': 'expo-checkbox2'}}) }}
        
{#check if the route is site_edit on display images#}
{% if app.request.attributes.get('_route') == 'site_edit' %}
        
    {% for image in site.media %}
        <div>
            <img
            src="{{ asset('/uploads/' ~ image) }}" alt="image" width="350">
            <a href="{{ path('sites_delete_image', {id:site.id}) }}" data-delete data-token="{{csrf_token('delete' ~ site.id )}}">Supprimer</a>
        </div>
    {% endfor %}
{% endif %}
{# {{ form_row(form.save) }} #}
<div>
<button class="btn btn-primary">{{ button_label|default('Save') }}</button>
</div>
{{ form_end(form) }}
    

</div>

And I have this error :

Argument 3 passed to Symfony\Component\Form\FormRenderer::searchAndRenderBlock() must be of the type array, string given, called in C:\Users\Diego\Dropbox\Mon PC (DESKTOP-HPQ395F)\Desktop\coursSymfony - Copie\ProjetEscalade4-4\var\cache\dev\twig\b9\b9349226432d99fda75ceac3109f9c1a1da36d5daf6021d355a04261335f80f7.php on line 104

Before I had an error with the practicabilitePiedsdesVoies field which is : Can't get a way to read the property "practicabilitePiedsdesVoies" in class "App\Entity\Site". and I put this 'mapped' => false in the builtform, and then I had the error above. Do you have an idea about how to solve this error? Thank you


Solution

Well if you read your error it tells you exactly that it is thrown "on line 104" of the cached twig file mentioned. That line will probably match the one line in your code that passes a third argument of type string:

    {{ form_label(form.practicabilitePiedsdesVoies, null, 'Practicabilité aux pieds des voies', {'attr': {'class': 'labbel3'}}) }}

I assume that string is meant to be the label text and therefore should be the second of three total arguments. So, you probably meant to write this:

    {{ form_label(form.practicabilitePiedsdesVoies, 'Practicabilité aux pieds des voies', {'attr': {'class': 'labbel3'}}) }}


Answered By - Arleigh Hix
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing