[luci] Custom buttons and functions

Jo-Philipp Wich xm at subsignal.org
Sat Sep 26 13:41:53 CEST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Hanno.

> You are suggesting the use of the CBI approach as oppose to the
> template/view approach by the previous respondent.

Not really, see below.

> Now the three approaches below seem to be tied to sections, which in
> turn have to be tied to a mapping to a schema. But would that not
> assumethe three kinds of buttons have to refer to the same
> /etc/config/file ? and if they do not (as is my case) does this mean
> these three button type cannot be on the same page?

Yes and no. You can coerce them into the same section by overriding some
default functions (most important cfgvalue and formvalue).

> And the action created in a function in the controller: Is that
> really creating a button on the screen? Or rather an action in
> response to an button still to be created on the page defined in  the
> corresponding model/cbi file?

It's not creating a button, just implements the action for it.

> Is there a principle advantage in the CBI approach versus the
> view/template approach proposed by the previous respondent?

The sole advantage of cbi in this specific case is the autogeneration of
forms. With call() actions in the controller and templates on the other
hand, you gain full control over both the program flow and the generated
markup at the expense of having to write the html yourself.

I'd suggest something like that in the controller:

page({...}, call("my_action"), ...)

function my_action()
	if luci.http.formvalue("do_something") then
		-- do something here and redirect
		luci.http.redirect("...")
	else
		-- render a template
		luci.template.render("my/template", {
			some = "value",
			to   = "pass",
			from = "controller"
		})
	end
end

This way the template rendering is wrapped into a function where you can
place your application logic.


> I may be very confused and therefore apologise for my ignorance in
> advance. I am not familiar with MVC kind of programming. I look
> forward to your advice.

No problem.


~ JoW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkq9/f4ACgkQdputYINPTPOamgCgoiAv66c2LCEK0Qob4y3E6Xto
poUAoIzKvw+oUsK3ntjgYMU7MdWpbF4u
=+YUL
-----END PGP SIGNATURE-----


More information about the luci mailing list