Closed nick-denry closed 7 months ago
Maybe you are right, as nav_id would be language independent.
The query should be changed to respect a current page language then, isn't it?
yii\web\NotFoundHttpException: Unable to find item with id 1 in /var/www/project/vendor/luyadev/luya-module-cms/src/frontend/controllers/DefaultController.php:68
Stack trace and DB Queries: trace-1.txt
Recap: The error occurs because there is no nav item of lang_id=2
(current language) and id=1
, compare SQL query in trace-1.txt
. The nav item with id=1
has lang_id=1
in your DB.
So in this case the use of 'childOf' => 2
would lead to the goal.
$this->_item = Yii::$app->menu->find()->where(['id' => $this->childOf])->with('hidden')->one();
ifnav_id
used instead ofid
menu item injected well but appears in left sidebar.
This is only possible due to your specific DB situation regarding nav_id=1
.
Maybe you are right, as nav_id would be language independent.
But then childOf
would have be transformed from a "childOfNavItem" to "childOfNav" property.
@hbugdoll what would you suggest?
On second thought, I think a Nav-related childOf
would fit better to be more versatile and then equal to menu item´s parent_nav_id
.
A typical use-case could be a submenu:
new InjectItem([
'childOf' => $parentNavId,
...
])
Yii::$app->menu->find()->where(['parent_nav_id' => $parentNavId])->all();
Another use-case could be injecting at root level, e.g. for offline items in PreviewController::actionIndex()
:
new InjectItem([
'childOf' => 0, // parent_nav_id = 0
...
])
:+1:
👍
After examining the source code of InjectItem
I see that the concept of inject item is based on a "real" parent menu item/NavItem (needed e.g. for alias concatenation or getting language).
So finding a parent menu item/NavItem is unfortunately not unambiguous from a Nav-related childOf
.
We should stay with status quo, but give a hint to the developer that the $parentItem
must be available for current language.
And add the alternative (and useful) inject option via parent item object
https://github.com/luyadev/luya-module-cms/blob/75a2afee6ca57e02ca5fe0df70eb077bdd0a7902/src/menu/InjectItem.php#L29-L37 to the guide https://luya.io/guide/cms/menu#menu-item-injection.
The submenu example above would become:
new InjectItem([
'childOf' => $parentItem.id
...
])
// or
new InjectItem([
'item' => $parentItem,
...
])
with access via
Yii::$app->menu->find()->where(['==', 'parent_nav_id', $parentItem.navId])->all();
@nadar When you agree with the above ⬆️, issues https://github.com/luyadev/luya-module-cms/issues/58 and https://github.com/luyadev/luya-module-cms/issues/62 could be closed.
sounds good :+1:
Hi!
I'm trying to inject menu item like it described in guide via placing following config to
components
section of theenv-local.php
Then I get error
That's what I got in log:
yii\web\NotFoundHttpException: Unable to find item with id 1 in /var/www/project/vendor/luyadev/luya-module-cms/src/frontend/controllers/DefaultController.php:68
Stack trace and DB Queries: trace-1.txt
This is my real
cms_nav_item
tableAssume that https://github.com/luyadev/luya-module-cms/blob/8fdc0d3cfa7ea0d03fd29cec91e21146ca39c861/src/frontend/controllers/DefaultController.php#L59 is not set somehow.
The problem related to this query: https://github.com/luyadev/luya-module-cms/blob/8fdc0d3cfa7ea0d03fd29cec91e21146ca39c861/src/menu/InjectItem.php#L108
if
nav_id
used instead ofid
menu item injected well but appears in left sidebar.