XF 2.2 How to correctly link to an "Add New Item" page

FoxSecrets

Member
I need a button to the "Add New Item" page.

So far I created the route and the button.

Code:
Route type: Admin
Route prefix: my-route
Subname: new

Code:
<xf:button href="{{ link('my-route/new') }}" icon="add">Add New Item</xf:button>

But when I click on the button, it redirects to main page, no change.

How to correctly link to the "Add New Item" page?
 
Are you routing to a controller you've created with an appropriate actionIndex method?
 
The actionIndex is the function to main page.

I don't know how to proceed with a button link to "Add New" page. Could you please give me directions?
 
The actionIndex is the function to main page.
If you're trying to route to the actionNew method, you don't need to create an additional route with the sub-name. Sub-names are automatically routed to controller actions, and creating additional routes with sub-names is typically for more advanced use cases (like routing them to a separate controller).
 
If you're trying to route to the actionNew method, you don't need to create an additional route with the sub-name. Sub-names are automatically routed to controller actions, and creating additional routes with sub-names is typically for more advanced use cases (like routing them to a separate controller).
But when I try to add "my-page/new" to Route prefix, I got error "Please enter a valid route prefix".

How to correctly route to New?
 
Your route prefix should be my-page (if it doesn't already exist). The sub-name should be blank. Then /my-page/new will route to the controller's actionNew method.
 
The my-page route already exists, that's the Index page (list all items). When I try what you said, I've got "Please enter a unique route prefix and sub-name. The specified combination is already in use.". Any suggestion?
 
Is your actionNew method on the same controller or a different controller? If it's on the same controller, /my-page/new will already route to it and there is no need to create another route, and any issues are likely coming from something in the controller action itself.

If it is a different controller, you can create a new route and set the sub-name to new, but your controller action should be actionIndex (as it is the index of the sub-route).

As ever, posting your controller code and screenshots of route configuration is helpful in trying to assist.
 
Top Bottom