zh Kooboo Logo Documents

Module

 

Additional Methods for Module Development
 
 
Basic Information
 
Retrieve the current URL and configuration information of the module.
 
k.module.baseUrl;
k.module.config; 
 
File
 
Accessing Local Files in the Current Module. Here are the available types of files:
 
k.module.localFile.api;
k.module.localFile.css; 
k.module.localFile.file;
k.module.localFile.img; 
k.module.localFile.js; 
k.module.localFile.view; 
 
Example of reading text:
 
k.module.localFile.css.writeText("abc.css", "div{color:red;}")
 
var result = k.module.localFile.css.readText("abc.css");  
k.response.write(result); 
 
IndexedDb
 
Accessing IndexedDB in the Current Module. You can operate on the IndexedDB instance within the current module using the same methods as described in the Database section. The only difference is that the module currently does not provide a database management interface.
 
Example of Insert and Read: 
 
var obj = {
    FirstName: "my first Name",
    LastName: "my last name"
}

k.module.localIndexedDb.newtable.add(obj); 
 
var list = k.module.localIndexedDb.newtable.all(); 
k.response.json(list); 
 
Sqlite
 
The module provides a local SQLite database that can be used similarly to the SQLite database in the site. 
 
var obj = {
    FirstName: "my first Name",
    LastName: "my last name"
}

k.module.localSqlite.newtable.add(obj); 
 
var list = k.module.localSqlite.newtable.all(); 
k.response.json(list); 
 
Schedule Task
 
To implement scheduled tasks in a module, you can utilize the built-in task scheduling functionality provided by Kooboo.
 
Here's an example:
 
k.task.minute(2).run(
    function () {
        var unPubLish = k.module.localDatabase.schedule.all();
        if (unPubLish) {
            unPubLish.forEach(
                function (o) {
                    if (o.date && o.date < Date.now) {
                        var content = k.content.blog.get(o.id);
                        if (content) {
                            content.Online = true;
                            k.content.blog.update(content);
                            k.module.localDatabase.schedule.delete(o.id)
                        }
                    }
                }
            );
        }

    }
);