Added NOTICE file
[project/luci.git] / src / ffluci / controller / public / example-action.lua
1 -- This example demonstrates the action dispatcher which invokes
2 -- an appropriate action function named action_"action"
3
4 -- This example consists of:
5 -- ffluci/controller/index/example-action.lua (this file)
6
7 -- Try the following address(es) in your browser:
8 -- ffluci/index/example-action
9 -- ffluci/index/example-action/sp
10 -- ffluci/index/example-action/redir
11
12 module(..., package.seeall)
13
14 dispatcher = require("ffluci.dispatcher").action
15
16 menu  = {
17         descr   = "Example Action",
18         order   = 30,
19         entries = {
20                 {action = "index", descr = "Action-Dispatcher Example"},
21                 {action = "sp", descr = "Simple View Template Stealing"},
22                 {action = "redir", descr = "Hello World Redirector"}
23         }
24 }
25
26 function action_index()
27         require("ffluci.template").render("header")
28         local formvalue = require("ffluci.http").formvalue
29         
30         local x = formvalue("x", nil, true)
31         
32         print(x and "x*x: "..tostring(x*x) or "Set ?x= any number")
33         require("ffluci.template").render("footer") 
34 end
35
36 function action_sp()
37         require("ffluci.http")
38         require("ffluci.i18n")
39         require("ffluci.config")
40         require("ffluci.template")
41         
42         -- Try uncommenting the next line
43         -- ffluci.i18n.loadc("example-simpleview")
44         ffluci.template.render("example-simpleview/index")
45 end
46
47 function action_redir()
48         require("ffluci.http").request_redirect("public", "index", "foobar")
49 end