XF 2.2 Admin route/navigation question

Anatoliy

Well-known member
Hardly understanding what I'm doing, but knowing that I need a admin navigation tab with sub links within, I created 3 routs and 3 links (for each of action in my controller). It worked just fine, until I understood that I didn't know what I'm doing. So I rebuild it and now I have 1 rout and 3 subnav links that have urls like route/actionName. Now I guess it's how it should be, it works, but the sublinks don't stay open when I click one of them, as it was before. Every time I click the link and then want to click another one, I have to click the "Add-on name" tab, it opens, and only then I can click the link.

Before those links pointed to individual routs, and those routs had the same Section context. How can I keep those links opened, if I can't use Section context for them?
 

DimmmCom

Active member
Hardly understanding what I'm doing, but knowing that I need a admin navigation tab with sub links within, I created 3 routs and 3 links (for each of action in my controller). It worked just fine, until I understood that I didn't know what I'm doing. So I rebuild it and now I have 1 rout and 3 subnav links that have urls like route/actionName. Now I guess it's how it should be, it works, but the sublinks don't stay open when I click one of them, as it was before. Every time I click the link and then want to click another one, I have to click the "Add-on name" tab, it opens, and only then I can click the link.

Before those links pointed to individual routs, and those routs had the same Section context. How can I keep those links opened, if I can't use Section context for them?
Specify the context in the controller method.
For example
PHP:
public function actionName()
{
    $this->setSectionContext('Admin navigation ID');

    //your code
}
 

Lukas W.

Well-known member
You can specify the context in the route declaration, no need to do it in your controller unless you need it to be dynamic
 

Anatoliy

Well-known member
And another question is about route format/Sub-name. I still can't digest the information and figure out which one should be used in my case.
I have actionDuplicates() in my controller that shows a list of duplicated thread titles. url is av-ttm/duplicates/ .
I want that clicks on a title link it would open a new window with details of those duplicate title threads (as title, first post date, last post date, number of posts). actionDuplicatesDetails() is responsible for that. When I started and made a route for every action, I could see how to tie it up. But now, when everything on one rout I stuck.
Please help me to unstuck. )

1.jpg

should titles be linked to ./admin.php?av-ttm/duplicates/{{$duplicate.title}}/ ?
or ./admin.php?av-ttm/duplicates/{{$duplicate.title}}/duplicates-details/ ?
or ./admin.php?av-ttm/duplicates/duplicates-details/{{$duplicate.title}}/ ?
 
Last edited:

Anatoliy

Well-known member
can I pass value of by post method? not via url?
admin.php?av-ttm/duplicates-details/ is the path, but when I try to add to rout av-ttm/ a route format :str<title>/
then it says The requested page could not be found. (Code: invalid_action, controller: AV\ThreadTitles\Admin\Controller\TitleController, action: ATitle) if the links is http://localhost/xf/admin.php?av-ttm/duplicates-details/a%20title/
and The requested page could not be found. (Code: invalid_action, controller: AV\ThreadTitles\Admin\Controller\TitleController, action: ATitleDuplicatesDetails)
if http://localhost/xf/admin.php?av-ttm/a%20title/duplicates-details/

I don't understand this route format/Sub-name thingy at all. 🤕
 

Kirby

Well-known member
this? it was there but didn't help.
Section context = av_ttm (the navigation ID of your section ) should work.

You don't want to use the title as a route parameter as it would be modfied and thus uesless for your usecase (see this thread - the title is "Admin route/navigation question" but the route-part became admin-route-navigation-question).
You want to pass this as a query parameter.

Code:
<a href="{{ link('av-ttm/duplicates-details', null, {"title":$duplicate.title}) }}">{$duplicate.title}</a>

PHP:
public function actionDuplicatesDetails(ParameterBag $params)
{
    $title = $this->filter('title', 'str');
  
    // do smth. with $title
}
 

Anatoliy

Well-known member
yep. changed section context to av_ttm, removed
$this->setSectionContext('av_ttm'); from controllers actions and everything works.

that's funny that when you are looking back in time you can't understand how it was possible to not understand what is the problem, if everything started to work properly after I put in actions setSectionContext('av_ttm')
🤭
 
Top