Menu

Maslosoft Framework Logo Maslosoft Framework Documentation
Flexible Application Foundation


Model Route Annotation

User defined named route annotation.

This annotation allow set any named route route for model. This should be placed on model class. This allows you to define route for any action, not just predefined like with other routing annotations. It is recommended to start route with slash /.

Example of named route. Will map myAction action to /module/controller/myOtherAction route. This is in case where action name is different from controller action name. While this is not recommended, might be required sometimes:

@ModelRoute('myAction', '/module/controller/myOtherAction', 'id')

To use more parameters, add them after coma (,):

@ModelRoute('myAction', '/module/controller/myOtherAction', 'id', 'parentId')

If name is omitted, it will be taken from action part of routing. This makes even easier defining routing. Will map myAction to /module/controller/myAction controller action:

@ModelRoute('/module/controller/myAction', 'id')

When params are empty, assume that id is required:

@ModelRoute('/module/controller/myAction')

To skip params completely, use false:

@ModelRoute('/module/controller/myAction', false)

Mapping parameters allows to bind one parameter to different parameter. This is useful for creating links from one model to other one.

@ModelRoute('createChild', '/module/controller/myAction', ['parentId' = 'id'])

When used with RouteMeta this will result in parameters having parentId key of value of id.

For example:

['parentId' => '51b616fcc0986e30026d0748']

Which together with Url or AbsoluteUrl might result in link:

https://example.com/content/page/update/parentId/51b616fcc0986e30026d0748

To remove param, or set static value, set parameter to scalar value, (excluding string). This might be useful to bind action for one parameter, but to exclude other one.

For example:

@ModelRoute('createChild', '/module/controller/myAction', ['parentId' = 'id', 'id' = null])

When used with GridButton will bind parentId but unbind id, so that action will be called with parentId only, thus resulting in new element with parentId set.