-
Notifications
You must be signed in to change notification settings - Fork 2
Add a Page
go to folder app/Controller and Create new JS file and with a class inside of it. the class name should be the same as the file name.
import view
from common
file
import { view } from "../../system/common.js";
the default method is usually called index, and all the methods have an argument called data
as a JSON object.
index = data => {return "the response message"}
otherMehodName = data => {return "the response message of the other method name"}
simply you can add routes by going to the file app/Config/Routes.js
,
and use router.get()
or router.post()
router.get(_routeUrl_, _ClassMethodString_)
if our class if named TestClass
:
//to access index method
router.get('/test', 'TestClass')
// or you can use
router.get('/test', 'TestClass::index')
//to access `otherMehodName`
router.get('/other/method/route', 'TestClass::otherMehodName')
to get information or GET data from the url, simply use {var_name}
in the route
router.get('/other/method/route/{id}/{date}', 'TestClass::otherMehodName')
so to access id
and date
from your method just use data.id
and data.date
to render the view from your method use return view(...)
view(_viewFile_, _jsonData_)
you should create your view file in app/View
and save it as ejs
,
like my_view.ejs
in your method use
return view('my_view',{title:"my title"})
and in your file simply use your data like
<h1> <%= title %> </h1>