Things you can register in the _init() function

  • Overview

    Every module will have an _init() function.

    This function will be in the xxModuleName/include.php file.

    The shortest definition for this function is:
    /**
     * init
     */
    function xxModuleName_init() {
        return true;
    }
  • When a module's _init() function returns nothing but 'true' it is just verifying that it exists.

    If the module wanted to declare any other things, this is where it would do it.

    Possible things it might like to declare are:

    * "Hey, I have a CSS file."

    * "Hey, I have a javascript file."

    * "Hey, I want to know when the user_signup event fires."

    * "Hey, I fire an event called 'save_media_file' in case anyone wants to listen for that."

    * "Hey, I provide a MagicView called 'image' for all modules to use. It takes care of displaying an image for a DataStore items so you don't need to write that functionality again."


    and more will be provided for by other modules yet to be created.

    The point is, the _init() function is where your module puts its hand up to tell the system what its doing.
  • Hey, I have a CSS file

    This will look for the css file located at:
    /xxModuleName/css/xxModuleName.css

    You can call the css file whatever you want
    /xxModuleName/css/i_love_dark_chocolate.css

    just make sure that name that you chose is the same as the one you use in the _init() function to register it.

    The recommended name for your main css file is (your module name).css
    jrCore_register_module_feature('jrCore', 'css', 'xxModuleName' 'i_love_dark_chocolate.css');
  • registering your css file like this will suck that file up into the sites main css file and compress it.

    This has many advantages for page loading speed.
    #1: the file is compressed to as small as it can be
    #2: when you work on it your working on an un-compressed copy so its readable.
    #3: since the CSS file remains the same across the site, it can be cached by your browser so it does not need to be re-loaded. That equals faster page load times.
  • Hey, I have a javascript file

    Registering that you have a javascript file has the same advantages as that of registering a CSS file. File compression, browser caching etc...

    Your modules javascript file will be looked for at:
    /xxModuleName/js/( the file name set in jrCore_register_module_feature() )

    So in this case it will look for xxModuleName.js
    jrCore_register_module_feature('jrCore', 'javascript', 'xxModuleName', 'xxModuleName.js');

Share This

Tags