您的位置:首页 > 运维架构

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

2015-10-08 09:42 369 查看
继上一篇:OpenWrt的luci web管理器添加新菜单

Call的方式:
在/usr/lib/lua/luci/controller/admin/new_tab.lua 文件中添加如下红色部分的内容:
-- Copyright 2008 fulinux <fulinux@sina.com>
-- 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

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: