Create a Controller
Controller are classes who handle routes and call Components
This is how to create a Controller
import AbstractController from "../Plasma/Abstract/AbstractController";
import Session from "../Plasma/Security/Session";
export default class AppController extends AbstractController {
constructor(name, isApp, core) {
super(name, isApp, core);
}
index() {
if (Session.isSession()){
PLASMA.routeManager.redirectTo("main")
}else{
PLASMA.routeManager.redirectTo("login")
}
}
unload() {
}
}
This controller is called "AppController" first of all you can see that it extend from AbstractController (provided by Plasma)
we have two important methods here :
index() if the main method called if no one are defined in the route
unload() is the method who gonna unload Pooled task (see PoolManager)
index()
On this index method we can see that the first operation is a Session check then we redirect to a route depending on Session state
Route:
the matching route for that controller should be
{
name: 'app',
path: '',
controller: "AppController",
isApp: true,
function: null,
params: null
}
Warning
If function is not null OR index, you have to create the function in your Controller. Applications: If you want to make a CRUD (Create, Read, Update, Delete) you probably want only one controller in this case you'll have 4 methods : index(); read(params); update(params); delete(params)
Get route params from Controller
if you pass params inside a method you'll have an Array of every parameters given by the url, you also can use RouteManager to get the params
Call a Component
To call a component simply instanciate it on the render method (index or the one you defined on route) DON'T FORGET THE IMPORT
new PanelComponent()
Last updated