64 |
65 |
66 |
Orbit Pages
67 |
68 |
Orbit Pages is a PHP-like programming environment built on top of Orbit. Orbit pages
69 | are HTML pages (but using the extension .op in a typical Orbit installation) that
70 | get dynamically converted into Orbit apps. They are launched by the op.cgi, op.fcgi
71 | and ophandler.lua launchers, for CGI, FastCGI, and Xavante, respectively. A standard
72 | Kepler installation includes support for Orbit pages by default.
73 |
74 |
An Orbit page is also a template that uses the Cosmo
75 | template language. The environment of this template is a sandbox that wraps the
76 | global environment and is recreated on each request. The main variable in this
77 | environment is the web variable, which is an Orbit request/response object.
78 | Other variables of note:
79 |
80 |
mapper - an instance of the default Orbit ORM
81 |
82 |
model(name, dao) - same as mapper:new(name, dao), except that if name
83 | is a tabel then calls mapper:new(name[1], name[2]), so you can use this in the
84 | template as $model{ name, dao }
85 |
86 |
app - the application's global environment, to be used as a session cache (for DB
87 | connections, for example) for persistent launchers
88 |
89 |
finish(res) - suspends the execution of the current page, and sends res as a
90 | response instead of the page's contents
91 |
92 |
redirect(target) - same as web:redirect(target) followed by finish(). If target
93 | is a table does web:redirect(target[1]), so you can use this in the template as
94 | $redirect{ target }
95 |
96 |
include(page, [env]) - evaluates the Orbit page in the file page (relative to the
97 | current page's path), optionally using the extra variables in env in the template's
98 | environment. Can also be used in the template as $include{ page, env }
99 |
100 |
forward(page, [env]) - aborts the execution of the current page and evaluates
101 | and sends the page in file page instead; otherwise same as include
102 |
103 |
There also a few more variables that should be used only in the template:
104 |
105 |
$lua{ code } - runs code in the same environment as the page, so
106 | code can change the template's variables and even define new ones
107 |
108 |
$if{ condition }[[ then-part ]],[[ else-part ]] - if condition is true then
109 | is replaced by the template evaluation of then-part, otherwise else-part. else-part
110 | is optional, defaulting to blank
111 |
112 |
$fill{ ... }[[ template ]] - replaced by the evaluation of template using the environment
113 | passed to fill (template does not inherit the variables of the page)
114 |
115 |
Below is a very simple Orbit page that shows most of the concepts above (including Cosmo
116 | concepts, see the Cosmo documentation for that):
117 |
118 |
#!/usr/bin/env op.cgi
119 | <html>
120 | <body>
121 | <p>Hello Orbit!</p>
122 | <p>I am in $web|real_path, and the script is
123 | $web|script_name.</p>
124 | $lua{[[
125 | if not web.input.msg then
126 | web.input.msg = "nothing"
127 | end
128 | ]]}
129 | <p>You passed: $web|input|msg.</p>
130 | $include{ "bar.op" }
131 | </body>
132 | </html>
133 |
134 |
135 |
The bar.op page it includes is this:
136 |
137 |
#!/usr/bin/env op.cgi
138 | <p>This is bar, and you passed $web|input|msg!</p>
139 |
140 |
141 |
The Kepler distribution has a more complete example that has database
142 | access, POST, and even some simple AJAX.
143 |
144 |
145 |
146 |
$n_comments Comments
22 | 23 | $comments[=[ 24 |