Helper

Helper

The Helper class which can be used as utility function. We support developers to extend Helper through ${baseDir}/app/extend/helper.js , then you can use all method on ctx.helper that is a instance of Helper.

Constructor

new Helper()

Source:

Methods

pathFor(name, params) → {String}

Generate URL path(without host) for route. Takes the route name and a map of named params.

Parameters:
Name Type Description
name String

Router Name

params Object

Other params

Source:
Example
```js
app.get('home', '/index.htm', 'home.index');
ctx.helper.pathFor('home', { by: 'recent', limit: 20 })
=> /index.htm?by=recent&limit=20
```

urlFor(name, params) → {String}

Generate full URL(with host) for route. Takes the route name and a map of named params.

Parameters:
Name Type Description
name String

Router name

params Object

Other params

Source:
Example
```js
app.get('home', '/index.htm', 'home.index');
ctx.helper.urlFor('home', { by: 'recent', limit: 20 })
=> http://127.0.0.1:7001/index.htm?by=recent&limit=20
```