# SW 5.2 createMenuItem

**URL:** <https://forum.shopware.com/t/sw-5-2-createmenuitem/38044>\
**Category:** Programmierung\
**Created:** [8. Juli 2016 um 07:34 UTC](https://forum.shopware.com/t/sw-5-2-createmenuitem/38044 "2016-07-08T07:34:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)\
**Post date:** [8. Juli 2016 um 07:34 UTC](https://forum.shopware.com/t/sw-5-2-createmenuitem/38044/1 "2016-07-08T07:34:56Z")

</div>

hi, in einem Plugin erstelle ich ein neues MenuItem

&nbsp;

```
$item = $this->createMenuItem(array(
            'label' => 'My-Item',
            'class' => 'sprite-drive-download',
            'active' => 1,
            'position' => 99,
            'action' => 'Index',
            'controller' => 'MyController',
            'parent' => $this->Menu()->findOneBy('label', 'Inhalte'),
        ));
        $this->Menu()->addItem($item);
        $this->Menu()->save();

```

&nbsp;

in SW 5.2.1 erhalte ich bei der Installation folgenden fehler:

&nbsp;

```
Unable to install, got exception:
An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2, t0.onclick AS onclick_3, t0.class AS class_4, t0.position AS position_5, t0.active AS active_6, t0.pluginID AS pluginID_7, t0.controller AS controller_8, t0.action AS action_9, t0.shortcut AS shortcut_10, t0.parent AS parent_11, t0.parent AS parent_12, t0.pluginID AS pluginID_13 FROM s_core_menu t0 ORDER BY LIMIT 1':

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1

```

&nbsp;

Hat sich hier in SW 5.2 etwas geändert? WIe erstelle ich ein Menüeintrag in SW 5.2?

&nbsp;

Vielen Dank

---

<div class="post-metadata">

**Author:** ![sschreier](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/sschreier/32/23296_2.png) [@sschreier](https://forum.shopware.com/u/sschreier)\
**Post date:** [8. Juli 2016 um 07:37 UTC](https://forum.shopware.com/t/sw-5-2-createmenuitem/38044/2 "2016-07-08T07:37:40Z")

</div>

> [@hbee schrieb:](https://forum.shopware.com/profile/1538/hbee "hbee")
> 
> hi, in einem Plugin erstelle ich ein neues MenuItem
> 
> &nbsp;
> 
> $item = $this-\>createMenuItem(array(  
> ‚label‘ =\> ‚My-Item‘,  
> ‚class‘ =\> ‚sprite-drive-download‘,  
> ‚active‘ =\> 1,  
> ‚position‘ =\> 99,  
> ‚action‘ =\> ‚Index‘,  
> ‚controller‘ =\> ‚HqsImport‘,  
> ‚parent‘ =\> $this-\>Menu()-\>findOneBy(‚label‘, ‚Inhalte‘),  
> ));  
> $this-\>Menu()-\>addItem($item);  
> $this-\>Menu()-\>save();
> 
> &nbsp;
> 
> in SW 5.2.1 erhalte ich bei der Installation folgenden fehler:
> 
> &nbsp;
> 
> Unable to install, got exception:  
> An exception occurred while executing ‚SELECT t0.id AS id\_1, t0.name AS name\_2, t0.onclick AS onclick\_3, t0.class AS class\_4, t0.position AS position\_5, t0.active AS active\_6, t0.pluginID AS pluginID\_7, t0.controller AS controller\_8, t0.action AS action\_9, t0.shortcut AS shortcut\_10, t0.parent AS parent\_11, t0.parent AS parent\_12, t0.pluginID AS pluginID\_13 FROM s\_core\_menu t0 ORDER BY LIMIT 1‘:
> 
> SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‚LIMIT 1‘ at line 1
> 
> &nbsp;
> 
> Hat sich hier in SW 5.2 etwas geändert? WIe erstelle ich ein Menüeintrag in SW 5.2?
> 
> &nbsp;
> 
> Vielen Dank

Hallo,

soweit mir bekannt ist, musste auch schon vor Shopware Version 5.2.0 ein Menüpunkt so erstellt werden:

```
$this->createMenuItem(array(
     'label' => 'Meine Beschriftung',
     'controller' => 'Meincontroller',
     'class' => 'settings--mail-presets',
     'action' => 'Index',
     'active' => 1,
     'parent' => $this->Menu()->findOneBy(['label' => 'Einstellungen'])
));

```

Der Unterschied liegt hier im Bereich parent und dem Array bei findOneBy(). addItem und save dürfte auch überflüssig sein.

Beste Grüße

Sebastian

---

<div class="post-metadata">

**Author:** ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)\
**Post date:** [8. Juli 2016 um 11:40 UTC](https://forum.shopware.com/t/sw-5-2-createmenuitem/38044/3 "2016-07-08T11:40:56Z")

</div>

hi, vielen Dank, das war’s.&nbsp;findOneBy() hat bislang aber so funktioniert. addItem und save ist nicht nur überflüssig sondern wirft in 5.2 auch einen Fehler.

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [8. Juli 2016 um 13:16 UTC](https://forum.shopware.com/t/sw-5-2-createmenuitem/38044/4 "2016-07-08T13:16:35Z")

</div>

Hallo,

vor SW 5.2 hatten wir die findOneBy Methode von Doctrine überschrieben, um auch mit zwei Strings zu arbeiten. Dies war aber eher ein unschöner Hack und hat auch mit PHP 7 Probleme bereitet. Deswegen wurde das entfernt und wir nutzen an der Stelle wieder den Doctrine Standard. Im gleichen Zuge sind auch die Methoden raus geflogen, die eh nichts gemacht haben, siehe:&nbsp;[shopware/Repository.php at 5.1 · shopware/shopware · GitHub](https://github.com/shopware/shopware/blob/5.1/engine/Shopware/Models/Menu/Repository.php#L36-L46)

Viele Grüße aus Schöppingen

![cool](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![TeichDatensysteme](https://avatars.discourse-cdn.com/v4/letter/t/43a26b/32.png) [@TeichDatensysteme](https://forum.shopware.com/u/TeichDatensysteme)\
**Post date:** [11. Juli 2016 um 09:51 UTC](https://forum.shopware.com/t/sw-5-2-createmenuitem/38044/5 "2016-07-11T09:51:35Z")

</div>

Da hatte ich Ende Mai bereits für ein Ticket erstellt, dort wurde es auch beantwortet:  
[https://issues.shopware.com/#/issues/SW-15183](https://issues.shopware.com/#/issues/SW-15183)

Schöne Grüße,  
Niklas
