OpenWrt的luci web管理器添加新菜单(二)

继上一篇:OpenWrt的luci web管理器添加新菜单


Call的方式:

在/usr/lib/lua/luci/controller/admin/new_tab.lua 文件中添加如下红色部分的内容:

-- Copyright 2008 fulinux <[email protected]>
-- Licensed to the public under the Apache License 2.0.


local fs = require "nixio.fs"


module("luci.controller.admin.new_tab", package.seeall) --notice that new_tab is the name of the file new_tab.lua
function index()
        entry({"admin", "new_tab"}, firstchild(), "New tab", 30).dependent=false  --this adds the top level tab and defaults to the
        entry({"admin", "new_tab", "tab_from_cbi"}, cbi("admin_myapp/cbi_tab"), "CBI Tab", 1)  --this adds the first sub-tab that is
        entry({"admin", "new_tab", "tab_from_view"}, template("admin_myapp/view_tab"), "View Tab", 2)  --this adds the second sub-ta
        entry({"admin", "new_tab", "action_counter"}, call("counter"), _("Click here"), 3).leaf = true
end


function counter ()
        local i = 0
        if fs.access("/var/run/test") then
                i = tonumber((fs.readfile("/var/run/test")))
        end
        i = i + 1
        fs.writefile("/var/run/test", string.format("%d\n", i))
        -- luci.http.redirect(luci.dispatcher.build_url("admin/new_tab/tab_from_view"))
        luci.http.write(tostring(i))
        return
end


这样你每次点击下面的菜单时都会跳转到一个页面显示你点击此菜单的次数:

OpenWrt的luci web管理器添加新菜单(二)_第1张图片


你可能感兴趣的:(Web,管理,openwrt)