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
这样你每次点击下面的菜单时都会跳转到一个页面显示你点击此菜单的次数:
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
这样你每次点击下面的菜单时都会跳转到一个页面显示你点击此菜单的次数:
相关文章推荐
- linux 网卡配置详解 ifcfg-eth0
- 如何恢复Windows引导
- linux CentOS 下设置 tomcat开机自启动
- 从零自学Hadoop(08):第一个MapReduce
- linux常用小命令
- centos安装g++
- tomcat conf
- SRM 667 DIV2 OrderOfOperationsDiv2 500-point
- java程序执行Linux命令
- 一步步安装nginx搭建流媒体服务器
- Linux系统目录
- Ubuntu必备软件
- Linux_1
- Property属性, KVC键值编码OC…
- Markdown编辑器中改变图片尺寸(eg:haroopad)
- Property属性, KVC键值编码OC…
- 网站论坛同步用户,整合api,实现…
- 网站论坛同步用户,整合api,实现…
- 如何在 Linux 中整理磁盘碎片
- 网站文件夹命名规则