[luci] Getting UCI configuration data

Jo-Philipp Wich xm at subsignal.org
Fri Jul 15 18:00:06 CEST 2011


Hi Matt,

your approach is fine, you just overlooked the fact that the "system"
section is anonymous so you cannot reference it by name.

The correct way would be:

  local hostname
  luci.model.uci.cursor():foreach("system", "system",
    function(s) hostname = s.hostname end)
  print(hostname)

Since this is often needed, we added a shortcut doing exactly that:

  local hostname = luci.model.uci.cursor():get_first("system", "system", "hostname")
  print(hostname)

See also http://luci.subsignal.org/api/luci/modules/luci.model.uci.html#Cursor.get_first

Also not that it must be  <%= expression %> instead of <% expression %>
if you want the result to be written onto the page.

Regards,
Jow


More information about the luci mailing list