luyadev / luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.
https://luya.io
MIT License
811 stars 205 forks source link

Unable to get additional property to all menu items #820

Closed uso5 closed 8 years ago

uso5 commented 8 years ago

I queried all menu items lets say with

Yii::$app->menu->find()->where(['parent_nav_id' => 0, 'is_active' => 1])->all()

I created page property - thumbnail image. Right now it is only possible to get additional properties to current page. I need to find this property to all menu items. Is it possible to implement?

nadar commented 8 years ago

So you would like to do something like this:

foreach(Yii::$app->menu->findAll(['parent_nav_id' => 0]) as $item) {

    $item->hasProperty('nameOf'); // returns bool
    $item->getProperty('nameOf'); // returns the value (otherwise false)
    $item->getProperties(); // returns the objects

}

am i right?

uso5 commented 8 years ago

@nadar you are right, thats what i am looking for.

nadar commented 8 years ago

Hi @uso5 i just implemented what you where looking for, sorry for the delay.

https://github.com/luyadev/luya/blob/master/docs/guide1.0/app-cmsproperties.md#in-menus

This will give you the ability to get the properties for the item. thanks for your feedback! indeed a very powerfull possbility. It even allows us to drop the Yii::$app->page->getProperty(...) as this is equals to new Yii::$app->menu->current->getProperty(...).

uso5 commented 8 years ago

Hi @nadar . Thank you for implementation. Looks very useful. I will use it 👍