代碼庫路徑: 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服務器從新創建索引後新頁面才能顯示