Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
using_helper_for_options [2018/08/26 12:33] – Add [Related Hooks] and [Sophisticated Usage]. Traumflug | using_helper_for_options [2019/01/28 18:48] (current) – [Parameter Description] Traumflug | ||
---|---|---|---|
Line 325: | Line 325: | ||
== ' | == ' | ||
Name of the HTML button. This is the name of the action PHP sees on submit. Defaults to // | Name of the HTML button. This is the name of the action PHP sees on submit. Defaults to // | ||
+ | |||
+ | Note: providing a name not matching one of the well known names (// | ||
== ' | == ' | ||
Line 398: | Line 400: | ||
</ | </ | ||
+ | ===== Panel with Multiple Tabs ===== | ||
+ | |||
+ | TODO: Helper can also separate fields into multiple tabs. For an example, see | ||
+ | AdminThemesController. Key to success is obviously an array ' | ||
+ | |||
===== Related Hooks ===== | ===== Related Hooks ===== | ||
'' | '' | ||
+ | |||
+ | ===== Making Variables Available for JavaScript ===== | ||
+ | |||
+ | In some cases it's necessary to forward variables from PHP to JavaScript. While the Helper engine has no direct support for this, there are options available. | ||
+ | |||
+ | |||
+ | ==== Using One Hidden Field Per Variable ==== | ||
+ | |||
+ | If only one, or only few variables need forwarding, using a [[Helper field ' | ||
+ | |||
+ | === PHP Code === | ||
+ | |||
+ | Snippet to insert as one of the [[Helper field|Helper fields]]: | ||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ], | ||
+ | </ | ||
+ | |||
+ | === JavaScript Code === | ||
+ | |||
+ | Example to use the value in JavaScript: | ||
+ | <code javascript> | ||
+ | console.log($(' | ||
+ | </ | ||
+ | |||
+ | === Caveats === | ||
+ | |||
+ | TODO: describe how to avoid storing the value in the database. | ||
+ | |||
+ | ==== Using One Hidden Field for Many Variables ==== | ||
+ | |||
+ | With JSON encoding, the same technique can be used for many variables: | ||
+ | |||
+ | === PHP Code === | ||
+ | |||
+ | Snippet to insert as one of the Helper fields: | ||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ])), | ||
+ | ], | ||
+ | </ | ||
+ | |||
+ | === JavaScript Code === | ||
+ | |||
+ | Example to use the value in JavaScript: | ||
+ | <code javascript> | ||
+ | let json = JSON.parse($(' | ||
+ | console.log(json.currentVersion); | ||
+ | console.log(json.repoApiUrl); | ||
+ | console.log(json.availableChannels); | ||
+ | </ | ||
+ | |||
+ | ==== Avoid Database Storage ==== | ||
+ | |||
+ | Especially when using fields just for passing parameters, one probably doesn' | ||
+ | |||
+ | === PHP Code === | ||
+ | |||
+ | The simple trick is to put an empty field handler method into the controller: | ||
+ | <code php> | ||
+ | public function updateOptionMycontrollerOption() { } | ||
+ | </ | ||
+ | That's all. For finding the required method name, see [[#Usage for Additional Tasks|above]]. | ||
===== Sophisticated Usage ===== | ===== Sophisticated Usage ===== |
using_helper_for_options.1535279624.txt.gz · Last modified: 2018/08/26 12:33 by Traumflug