首页 > Web开发 > 详细

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

时间:2015-10-08 10:37:49      阅读:518      评论:0      收藏:0      [点我收藏+]

继上一篇: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


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

技术分享


版权声明:本文为博主原创文章,未经博主允许不得转载。

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

原文:http://blog.csdn.net/fulinus/article/details/48968727

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!