Documentation | NWICODE

The module can be one main page with a new feature or setting,or a complete function that can be used in your mobile applications and managed in your editor applications.

Modules are installed inapp/local/modulesfolder

Composition

The folder structure

ModuleName
├─ Controller
│  └─ Default.php/** If you need to override the default controller Classes */├─ controllers
│  ├─ Backoffice
│  │  └─ ModuleNameController.php
│  └─ Mobile
│     └─ ModuleNameController.php
├─ features
│  └─ [...]// Core feature related files├─ Form
├─ Model
├─ View
├─ resources
│  ├─ db
│  │  ├─ data
│  │  └─ schema
│  ├─ media 
│  │  └─ library
│  ├─ translations
│  │  ├─ default
│  │  │  └─ mymodule.po
│  │  ├─ en
│  │  └─ [...]
│  └─ design
└─ package.json

the basics

package.json

package.jsonUsed by the installer to start the installation process / upgrade

{
  "name":"ModuleName",
  "description":"Module description",
  "type":"module",
  "version":"1.0",
  "dependencies":{
    "system":{
      "type":"SAE",
      "version":"1.0.0"},
    "modules":{
      "OtherModule":"1.1.0"}
  }
}

resources/db/schema

We useresources/db/schema/table_name.phpto describe the schema of the table; below is an example of the base table.

This file (s) reflect your database to the latest version every time you update your module, the local scheme is compared with this file and upgrade

Note: the scheme adds a field only if they are new or do not exist, the fields are never deleted.


/**
 * Schema definition for "table_name"
 */
$schemas= (!isset($schemas)) ? [] :$schemas;$schemas["table_name"] = ["mytable_id"=> ["type"=>"int(11) unsigned","auto_increment"=>true,"primary"=>true,
    ],"admin_id"=> ["type"=>"int(11) unsigned","is_null"=>true,"foreign_key"=> ["table"=>"admin","column"=>"admin_id","name"=>"FK_MY_MODULE_ADMIN_ID_ADMIN_AMIN_ID", // Must be unique!
            "on_update"=>"CASCADE","on_delete"=>"CASCADE",],   
    ],"name"=> ["type"=>"varchar(50)","default"=>"default_value","index"=>true,
    ],"created_at"=> ["type"=>"datetime",
    ],"updated_at"=> ["type"=>"datetime",
    ],
];

The list of available options

key Type The use, value, comment
type
line int (11) unsigned varchar (50), datetime, etc ...
auto_increment
logical
primary
logical
is_null
logical
default
mixed
foreign_key
Array ()
foreign_key
Array ()

Parameters foreign key

key Type The use, value, comment
table
line Reference table
column
line The reference column in the table
name
line The name of the foreign key (for example, FK_TABLENAME_KEYNAME_REFTABLENAME_REFKEYNAME)
on_update line NO ACTION, SET NULL, CASCADE, CONSTRAINT
on_delete line NO ACTION, SET NULL, CASCADE, CONSTRAINT

Index options

key Type The use, value, comment
key_name line The index name, use the same in multiple columns for composite indexes
index_type line TREE, HASH
is_null
logical
is_unique logical

resources/db/data

This folder is used to insert default values during install or upgrade the module.

Every php file in this folder will run when installing and / or updating module, they must reflect the necessary data as the latest version.

Protected names:install.php%VERSION%.phpwhere% VERSION% is the string semver, you NEVER have to use them.

Best practice:

  • If your module is going to install multiple functions, split them into several files

    • for example:feature1.phpfeature2.phpetc ...

features/modulename/feature.json


This file is key for all functionsapplication

{
    "name":"ModuleName",
    "code":"modulename",
    "version":"1.0.0",
    "category":"contact",
    "model":"ModuleName_Model_MainClass",
    "desktop_uri":"modulename/application/",
    "routes":[
        {
            "root":true,    "state":"modulename-home",    "controller":"ModuleNameHome",    "url":"modulename/mobile_home/index/value_id/:value_id",    "template": "l1/home.html",
            "cache": false
        },
        {
            "state": "modulename-view",
            "controller": "ModuleNameView",
            "url": "modulename/mobile_view/index/value_id/:value_id/item_id/:item_id",
            "template": "l1/view.html",
            "cache": false
        }],
    "layouts": [1],
    "icons": ["icons/modulename1-flat.png",
        "icons/modulename2-flat.png",
        "icons/modulename3-flat.png"],
    "files": ["js/services/modulename.js",
        "js/factory/modulename.js",
        "js/controllers/modulename.js",
        "scss/modulename.scss"
    ],
    "compile": true,
    "use_account": true,
    "only_once": true,
    "load_on_start": false,
    "on_start_factory": null
}

The list of options

key Type The use, value, comment
name
line Your function name
code
line This code is unique to your function module
category
line socialmediacontactmonetizationcustomizationintegrationevents,misc
version
line Not used here, seePackage.jsonfor version
model
line The model class by default used in the editor
desktop_uri line Class of the default controller used in the editor
compile
logical Expresstrueby default
use_account logical If the function requires that the user logged in, settrue
only_once
logical If your app can have that feature only once or more
load_on_start logical If the function to be loaded immediately after application startup
on_start_factory line Whenload_on_startsettrue, the function Factory.onStart whereFactory- the name of the class

Translations

Uses files.powhich are the source files of Gettext .

First, create a new file namemymodule.pothen place this file intranslations/defaultfolder

If you want to send your module with translations, place the files in a directory named with the locale ID, for example: english will betranslations/en/mymodule.po

Below is an examplecontact.pofile.

Definitely do not use the existing file name, which isNWICODECMS_ROOT/languages/baseanother place, otherwise your translations won't work.

msgid""msgstr""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2019-03-28T15:24:21+01:00\n"
"PO-Revision-Date: 2019-03-28T15:24:21+01:00\n"
"Language: \n"msgctxt"contact"msgid"Cover image"msgstr"Illustration"msgctxt"contact"msgid"Name"msgstr"Name"

#, mobilemsgctxt"contact"msgid"Facebook"msgstr"Facebook"

#, mobilemsgctxt"contact"msgid"Twitter"msgstr"Twitter"

#, mobilemsgctxt"contact"msgid"Website"msgstr"Site web"msgctxt"contact"msgid"String to translate"msgstr"Sentence to translate"msgctxt"contact"msgid"Hello, I'm %s"msgstr"Hello I am %s"

The list of options

key Type The use, value, comment
#, mobile
line Add this line if the line is translated inside mobile apps
msgctxt
line This is your shortcut key usually is a code module
msgid
line Original string used as the key
msgstr
line In the folder fordefaultmsgstr = msgidin the file transfer msgstr - translated sentence.

How to translate

Internal editor and office


Mobile apps the key notes and context are reversed compared to the php function

// From the controllers, include $translate factory
$translate.instant("Hello, I'm %s", "context_key");
// From any template
{{ "Hello, I'm %s" | translate:"context_key" }}

design

All you need isdesign

ModuleName
├─ [...]
├─ resources
│  └─ design
│     ├─ desktop
│     │  └─ flat
│     │     ├─ css
│     │     │  └─ modulename.css
│     │     ├─ js
│     │     │  └─ modulename.js
│     │     ├─ images
│     │     │  └─ customization
│     │     │     └─ layout
│     │     │        └─ modulename
│     │     │           ├─ layout-1.png
│     │     │           └─ layout-2.png
│     │     ├─ layout
│     │     │  └─ modulename.xml
│     │     └─ template
│     │        ├─ company
│     │        │  └─ [...]
│     │        └─ modulename
│     │           ├─ index.phtml
│     │           └─ application
│     │              ├─ edit.css
│     │              ├─ edit.js
│     │              └─ edit.phtml
│     └─ email
│        ├─ layout
│        └─ template
└─ [...]

Example modulename.xml

This is the minimum information by defaultlayout.xmlthe file must be named like the module itself, andjob.xml in our case, in lower case.



    
        
            
            
        
    


Sectioncontent tab is the default tab of the function editor, you don't need to change it.

Sectioncontent_editor should point to the template object editor

here: a short way withmodulename/application/edit.phtml linkModuleName/resources/design/template/modulename/application/edit.phtml

  • Use only a short way.

cache

When developing a module, you will have to manually rebuild what we call the design cache

Note: when installing and / or updating the module using the normal zip package, the cache is automatically cleared for the users.

Background image

Side editor

In the edit file.phtml that handles the editor interface for your module, you should add a background section as shown below.

importBackground($option_value); ?>

It's as simple as the code below, as all associated with this function and automatically cropped / saved for you.

Application / Ion

Then, to make sure that your background image on the pages app, you have to make sure that all views and lists, it also uses a new Directive sb-page-background


    {{ "My Awesome Content!" |translate:"module_name" }}

package

When you're finished with your module, it's time to pack!

Archive all in the root of your module and you're done!

ModuleName.zip
├─ Controller
├─ controllers
│  └─[...]
├─ features
├─ Model
├─ View
├─ resources
│  └─[...]
└─ package.json


Есть вопросы — спрашивайте!

Наши специалисты помогут Вам, окажут бесплатную консультацию или запишут на приём

Documentation

Новости 1 - 20 of 48
First | Prev. | 1 2 3 | Next | Last