Summary of the initial attempt of the web framework under OpenWRT, openwrtweb
Web summary under OpenWRT
Contents
Table of Contents 1
Chapter 1 Web framework and implementation 2
Section 1 luci framework 2
Section 2 Write a file (*. lua) under controller 2
Section 3 File (*. lua) under model 3
Section 4 file (*. htm) under view 4
Chapter 2 web access process 5
Chapter 3 lua learning materials 6
References 7
Chapter 1 Web framework and implementation
Section 1 luci framework
OpenWRT web adopts the luci framework, which adopts the MVC design mode. The luci directory contains three important directories: controller, model, and view. Place the front-end htm file under view, the logical control file under controller, and some templates mapped to generate htm under model.
Controller Directory: organizes all the "logical processing" used by registering "Tree nodes. That is to say, all logical processing is organized like the branches and leaves of a tree.
Model: Business processing and htm production templates.
View: htm file.
Online references:
Http://www.verydemo.com/demo_c101_i48675.html
Http://www.verydemo.com/demo_c101_i42459.html
Section 2 Write a file (*. lua) under the controller
As described in section 1, the controller acts as a logical organization in the luci framework. The encoding is divided into two parts:
1 "branch registration" --- module Registration
2 "leaf registration" --- node Registration
Module 1 Registration
For example, module ("luci. controller. admin. system", package. seeall)
Description: registers a system module under luci/controller/admin /.
2-node Registration
Row 1: function index ()
Row 2: entry ({"admin", "system", "system"}, cbi ("admin_system/system"), _ ("System"), 1)
Row 3: end
Rows 1 and 3 represent a function block.
Row 2: Indicates registering a system node under the admin/system module. The node sequence is 1 and cbi (discussed later)
Note: The fourth parameter sequence in Row 2 is very important. It will affect the display sequence on the web.
Entry () function analysis:
Parameter 1: The name of the inserted node, for example, {"admin", "system", "heyg1"}, indicates that the node heyg1 is inserted in the system of admin.
Parameter 2: The following methods are usually used to insert the heyg1 node:
Method 1: template Method. When this node is called, the corresponding htm file under view is directly called.
Method 2: The cbi/form method calls the corresponding files under the model for corresponding processing.
Method 3: call method, which calls the function of this file or the imported File
Other methods:
Alias: Indicates link to another node.
Here, the template ("heyg/heyg1") will call the view/heyg/heyg1.htm File
Parameter 3: The name of the inserted node at the corresponding position. The name is displayed in the corresponding menu on the web interface.
Here _ ("heyg1") is displayed as heyg1 in the web menu
Parameter 4: insert different types of nodes of the same level, or distinguish the numerical codes of other nodes of the same level.
Here, 3 cannot be the same as other options at the same level.
In the intermediate menu, the display is from small to large, such as: system (1), Administration (2), heyg1 (3 )....
Some attribute parsing of the Entry () function: for inserting a node, this node has some attributes in addition to the corresponding name and processing action, we can manually set its property value similar to entry (). dependent = false
The following attributes are provided on the official website:
Dependent: when the parent node of the node is lost, the node is protected so that it is not accidentally called.
Leaf: if there are other sub-nodes under the node, the sub-nodes will not continue to be parsed when the node is resolved to the end point.
Sysauth: A system account is required for verification when you use this node.
I18n: defines which files will be automatically loaded when a page request is requested.
Other attributes (purely self-guessed. If any error occurs, please do not spray them ):
Index: this node is used as the home page or the first page by default under the same level directory.
Official Website: http://luci.subsignal.org/trac/wiki/Documentation
Blog: http://blog.csdn.net/ubuntucc/article/details/41083687
Section 3 File (*. lua) under model
Http://www.tuicool.com/articles/zaUNfy
Http://blog.chinaunix.net/uid-23780428-id-4367351.html
Section 4 file (*. htm) in view
Embedded lua scripts, htm, and js statements
Chapter 2 web access process
Http://blog.chinaunix.net/uid-23780428-id-4367414.html
Web Data Interaction in http://www.cnblogs.com/gnuhpc/archive/2013/08/31/3293643.html
Chapter 3 lua learning materials
English manual:
Http://www.lua.org/manual/5.1/index.html
Chinese manual:
Http://www.codingnow.com/2000/download/lua_manual.html
Lua Tutorial:
Http://lua-users.org/wiki/TutorialDirectory
Function interfaces used in most lua Statement Analysis:
Http://blog.csdn.net/chinazhd/article/details/7776994
Blogs and learning ARTICLES OF NB
Http://blog.csdn.net/xoyojank/article/details/12762909
Http://xuzhihong1987.blog.163.com/blog/static/26731587201171152614685/
References
Configure Makefile on LuCI:
Http://luci.subsignal.org/trac/wiki/Documentation/Modules
CBI:
Http://luci.subsignal.org/trac/wiki/Documentation/CBI
Luci:
Http://luci.subsignal.org/trac/wiki/Documentation/ModulesHowTo
Luci Class Library Function Definition and usage instructions:
Http://luci.subsignal.org/api/luci/index.html
UCI interface:
Http://wiki.openwrt.org/doc/devel/config-scripting