Developer Question: New Module
I am creating a rather in depth module. There is no documentation for most of the functions within modules. The test module has no documentation outside of a few simple things.
I'm starting this thread to get some answers and have a common place to ask and seek answers.
Where do I add in my inclusion for main.js so it is only loaded on my modules page. I have no reason for it to be included site-wide. Every module I look at adds the AddJs('main.js') in different places. Where is the correct place?
-
-
·
LeonidS
- ·
Hello @Wise !
The simplest way is to call the addJs template method in any place before it is necessary.
But if you have in your module own _header.html template file then you may add your files to preloader like:
INSERT INTO `sys_preloader` (`module`, `type`, `content`, `active`) VALUES ('you module name', 'js_system', 'modules/[your name]/[name of your module]/js/|name of your file.js', 1);
-
·
LeonidS
-
- · Wise
- ·
That would include it every page load.
I simply want it included on my modules pages. I get even more confused the more I look, because AddJs and AddCss are never in the same place. So your saying I could call the AddJs in my service block code?
See, I'm getting lost because one thing UNA doesn't have, is a developer structure. Everyone kind of just does it however until it works. There should be a clear place to add js if I want it included on my modules pages alone. Same with AddCss
Will this add it to the gzip, cached output?
-
-
·
Alexander
-
·
In reply to Wise
- ·
The general rule is to call the addJs|Css whenever needed. I.e. if the template method depends on some JS or CSS then call addJs|Css in that method for the related files. Also instead of having a large single main.js where you put all of the code regardless of a page/section/block it is better to have logically separated files (view.js, edit.js, view.css, manage.css, etc.) and add/include them where necessary in the respective methods, blocks.
In case for some reason you'd like your main.js to be included always for all of your module's pages then you may try to put the addJs into the template's constructor.
And yes, the caching and gzipping happens automatically.
-
·
Alexander
-
- · Wise
- ·
@LeonidS and @Alexander thank you for the replies. 🙏
That makes sense now. 😁 And in my testing worked perfectly. Now I understand why AddJs and AddCss are never in the same place. Call them as necessary. Noted. 👍
-
- · Wise
- ·
Next question...
Is UNA session variable safe? Meaning, I am interacting in a popup to show stages of an application. And displaying ajax responses within a popup. There are many steps.
This information is sensitive, and even with https I do not want to round robin information.
Is it safe to use $_SESSION in UNA?
-
- · Wise
- ·
Another question. What are all the predefined methods available to our classes?
Example
$this->_oTemplate-> is not defined by me, but is available in my module to interact with template class.
What else is available? Or where are these defined so I can look through the code myself?
-
-
·
LeonidS
-
·
In reply to Wise
- ·
You may check all parents of your Module class. The first parent, inc/classes/BxDolModule.php file has the following settings:
public $_aModule; public $_oDb; public $_oTemplate; public $_oConfig;
the values of all these variables are assigned in the constructor.
-
·
LeonidS
-
-
-
·
LeonidS
-
·
In reply to Wise
- ·
How to work with the Cron Jobs. First of all, your module should have the record in the sys_cron_jobs table. See the example from the Timeline app
INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES ('bx_timeline_hot', '0 * * * *', 'BxTimelineCronHot', 'modules/boonex/timeline/classes/BxTimelineCronHot.php', '');
In the time field, you may set the proper timing of your Cron, if you fill the class field then your app should have the file with the mentioned class. The Cron class must have the processing method, which will be run during this scheduling.
Please specify about relations - what do you need to do with that?
-
·
LeonidS
-
- · Wise
- ·
I want to be able to integrate with timeline module to put additions to timeline. It seems the modules that do this have a 'relations' array in config.php .
In the enable section
'update_relations' => 1,
Then, there is a section
'relations' => array( 'bx_timeline', 'bx_notifications' )
I would like to understand these.
And what all is necessary to send notifications, add to timeline, etc.