Why do I get A Twig Error Runtime when trying to access my list of field ?

1,642 views
Skip to first unread message

Dekker

unread,
Jul 18, 2012, 10:42:05 AM7/18/12
to sonat...@googlegroups.com
I've successfully implemented the Sonata Bundle, and did all that I have to do for the first 4 chapter of the official documentation. Thus, When trying to click on "add new' or 'list', I got this weird errror :


"

An exception has been thrown during the rendering of a template ("Notice: Array to string conversion in C:\Program Files (x86)\wamp\www\QNetworks\app\cache\dev\twig\eb\15\e380e4858b5d5bc113630bd4d095.php line 206") in SonataAdminBundle::standard_layout.html.twig at line 121.


"

Does anyone could help me to find out where does that come from ? (I mean why ? What should I do to fix it ? Because my tables are regular MySQL tables with strings in each fields, there is no reason why there should be an array commig out from one of these fields.

here are lines 114 to 131, line 121 is in red, i've noticed that if I get rid of {{uri}} variable, I don't have this error anymore. Does anyone knows where is this variable from and for ?

        <div class="container-fluid">
            {% if _breadcrumb is not empty or action is defined %}
                <ul class="breadcrumb">
                    {% if _breadcrumb is empty %}
                        {% if action is defined %}
                            {% for label, uri in admin.breadcrumbs(action) %}
                                {% if not loop.last  %}
                                    <li><a href="">{{ label }}</a><span class="divider">/</span></li>
                                {% else %}
                                    <li class="active">{{ label }}</li>
                                {% endif %}
                            {% endfor %}
                        {% endif %}
                    {% else %}
                        {{ _breadcrumb|raw }}
                    {% endif %}
                </ul>
            {% endif %}

I also want to add my admin class :
<?php
namespace QN\MainBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
class CategoryAdmin extends Admin
{
    public function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('name')
            ->add('level')
        ;
    }
    public function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General')
                ->add('name', 'sonata_type_model', array(), array('edit' => 'list'))
                ->add('level')
            ->end()
        ;
    }
    public function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
            ->add('level')
        ;
    }
    public function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('name')
            ->add('level')
        ;
    }
}
Thank you !

jeromebailleul

unread,
Jul 20, 2012, 4:55:44 AM7/20/12
to sonat...@googlegroups.com
Hi,

i have the same problem. To avoid this error, i do that :

Replace line 121 in standard_layout.html.twig

<li> <a href="{{ uri.uri }}"> {{ label }} </ a> <span class="divider"> / </span> </li>

by  

<li> <a href="{{ uri }}"> {{ label }} </ a> <span class="divider"> / </span> </li>

It's not the final solution (i discover Symfony since 2 days) because the beadcrumb don't work but the bundle works

I hope another people will find a best solution

Jerome

P.S : sorry for my english ;)

jeromebailleul

unread,
Jul 20, 2012, 4:59:51 AM7/20/12
to sonat...@googlegroups.com
  • i forget the path of the file vendor\bundles\Sonata\AdminBundle\Resources\views\standard_layout.html.twig 

Backender

unread,
Jul 24, 2012, 3:27:04 AM7/24/12
to sonat...@googlegroups.com
To me the default was:
<li> <a href="{{ uri }}"> {{ label }} </ a> <span class="divider"> / </span> </li>
(they might have changed now)

But it'll only work with:

<li> <a href="{{ uri.uri }}"> {{ label }} </ a> <span class="divider"> / </span> </li>

Do you have an idea how to fix that withoud modify this template?

jeromebailleul

unread,
Jul 24, 2012, 3:34:59 AM7/24/12
to sonat...@googlegroups.com
No, a this moment i accept this solution. Hope another people will find a best solution.

Regards,

Jerome

Backender

unread,
Jul 24, 2012, 3:50:12 AM7/24/12
to sonat...@googlegroups.com
Just noticed that i've no names in the navigation bar on the top!
It's not like: Posts/Create/...
Only have: 0/1/2...

Could this be in relation with the error i get in standard_template? array to string?!
I have a __toString in my entity, this shouln't be the problem.

Thomas Rabaix

unread,
Jul 24, 2012, 4:44:46 AM7/24/12
to sonat...@googlegroups.com
you need to use the correct version of KnpMenu, see

https://github.com/sonata-project/sandbox/blob/2.0/deps#L86


--
You received this message because you are subscribed to the Google Groups "sonata-devs" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sonata-devs/-/zNJ2u3zzO1MJ.

To post to this group, send email to sonat...@googlegroups.com.
To unsubscribe from this group, send email to sonata-devs...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sonata-devs?hl=en.



--
Thomas Rabaix
http://rabaix.net | http://sonata-project.org

Marc Juchli

unread,
Jul 24, 2012, 5:54:14 AM7/24/12
to sonat...@googlegroups.com
Works! thanks.

(Note: had to remove target of KnpMenu to get it working)


Gesendet mit Sparrow

Annoncez Vite

unread,
Jul 24, 2012, 6:31:28 AM7/24/12
to sonat...@googlegroups.com
Me too ! Thanks a lot

2012/7/24 Marc Juchli <ma...@mjnet.ch>
Reply all
Reply to author
Forward
0 new messages