代码库路径: feeds/lluci/applications/luci-myapp/luasrc/controller/myapp.lua
设备上路径: /usr/lib/lua/luci/controller/myapp.luahtml
格式:web
module("luci.controller.myapp", package.seeall) function index() end
注册URL:服务器
entry(path, target, title=nil, order=nil)session
target分别有:app
actions
使用函数直接输出内容函数
call("my_fun")ui
views
使用htmllua
template("mymodule/myview")url
cbispa
cbi("mymodule/mycbi")
例如
function index() entry({"admin", "services", "mymodule", "mycbi"}, cbi("mymodule/mycbi"), _("CBI")).leaf = true entry({"admin", "services", "mymodule", "myview"}, template("mymodule/myview"), _("View")).leaf = true entry({"admin", "services", "mymodule", "myfun"}, call("my_fun"), _("FUN")).leaf = true end
代码库路径: feeds/luci/applications/luci-myapp/luasrc/model/cbi/myapp.lua
设备上路径: /usr/lib/lua/luci/model/cbi/myapp.lua
/etc/config/ipsec配置文件以下
config policy tunnel option name 'test' option enable '1'
建立UCI配置文件ipsec对应的map对象
m = Map("ipsec", translate("IPSec"))
建立UCI type对象
s = m:section(TypedSection, "policy", translate("Polciy")) s.template = "cbi/tblsection" -- 使用列表模板 s.anonymous = true -- 不显示section名称
建立UCI name对象
s = m:section(NamedSection, "tunnel", "policy", "translate("Policy"))
建立UCI option对象
name = s:option(DummyValue, "name", translate("Name")) enable = s:option(Flag, "enable", translate("Enable)) enable.rmempty = false -- 值为空时不删除
参数说明:
方法说明:
:section(sectionclass, ...)
参数说明:
section
type
section对象属性:
.addremove = false
此section是否容许删除或建立
为true时,页面会显示删除
和建立
按钮
.anonymous = true
页面不显示此secion名字
方法说明:
:option(optionclass, ...)
参数说明:
type
section对象属性:
.addremove = false
此section是否容许删除或建立
为true时,页面会显示删除
和建立
按钮
.anonymous = true
页面不显示此secion名字
.extedit = luci.dspatcher.build_url("url")
设置此section编辑页面URL, 页面显示
编辑
按钮
.template = "cbi/template"
设置此section页面模板
方法说明:
:option(optionclass, ...)
页面将建立文件输入框
参数说明:
enable
'1'属性说明:
.defalut = nil
缺省值
.maxlength = nil
option值最大长度
.rmempty = true
option值为空时不写入UCI文件
.size = nil
页面表单对应位置大小
.optional = false
是否为可选,为true可强制页面输入
.datatype = nil
指定option值类型,用于输入合法性检查
.template = nil
页面模板
.password = false
密码输入框
方法说明:
:depends(key, value)
当key值等于value时,页面才显示
function o.validate(self, value)
end
重构option合法性检查方法,可本身控制option值
function o.formvalue(self, key)
end
重构option从表单获取值方法
当表单值为空时返回-
,在合法性检验时判断若是value等于-
即表示页面没有输入值
function o.formvalue(...) return Value.formvalue(...) or "-" end function o.validate(self, value) if value == "-" then return nil, translate("required fields have no value!") end return value end
functin o.write(self, section, value)
end
重构option写入UCI文件方法
在用户输入的值后追加内容s
:
function o.write(self, section, value) Value.write(self, section, value .. "s") end
function o.cfgvalue(self, section)
end
重构option值输出到页面方法
页面只显示UCI option值开始为数字部份内容:
function o.cfgvalue(self, section) local v = Value.cfgvalue(self, section) if v then return string.sub(v, string.find(v, "%d+")) else return nil end end
页面将建立列表框
参数说明:
action
'drop'属性说明:
同class Value
方法说明:
同class Value
:value(ucivalue, showkey)
设置下拉列表显示与值对应关系
o = s:option(ListValue, "enable", translate("Enable")) o:value("1", translate("Enable")) o:value("0", translate("Disable"))
页面将建立单选框
参数说明:
enable
'0'属性说明:
同class Value
方法说明:
同class Value
页面将建立按钮
参数说明:
enable
'0'属性说明:
同class Value
.inputstyle = nil
按钮样式,
apply
,reset
,
方法说明:
同class Value
代码库路径: feeds/luci/applications/luci-myapp/luasrc/view/myview.htm
设备上路径: /usr/lib/lua/luci/view
定义本身的html模板
原有模板路径: feeds/luci/modules/base/luasrc/view/cbi/目录
当设备更新了control文件后,页面不会显示,需把/tmp/目录下luci-indexcache
luci-modulecache/
luci-sessions/
删除,web服务器从新创建索引后新页面才能显示