我想回顾一下这个事实 elgg_view_input()已弃用 Elgg v2.3.4
$footer = '';
foreach ($controls as $control) {
$type = elgg_extract('input', $control, 'text');
unset($control['input']);
$footer .= elgg_view_input($type, $control);
}
答案 0 :(得分:1)
改用elgg_view_field()。
示例#1
<?php
echo elgg_view_field(['#type' => 'text', 'name' => 'sitename', '#label' => elgg_echo('installation:sitename'), 'value' => elgg_get_config('sitename')]);
echo elgg_view_field(['#type' => 'text', 'name' => 'sitedescription', '#label' => elgg_echo('installation:sitedescription'), 'value' => elgg_get_config('sitedescription')]);
echo elgg_view_field(['#type' => 'email', 'name' => 'siteemail', '#label' => elgg_echo('installation:siteemail'), 'value' => elgg_get_site_entity()->email, 'class' => 'elgg-input-text']);
echo elgg_view_field(['#type' => 'number', 'name' => 'default_limit', '#label' => elgg_echo('installation:default_limit'), 'value' => elgg_get_config('default_limit'), 'min' => 1, 'step' => 1]);
echo elgg_view_field(['#type' => 'select', 'name' => 'language', '#label' => elgg_echo('installation:language'), 'value' => elgg_get_config('language'), 'options_values' => get_installed_translations()]);
$footer = elgg_view('input/submit', ['value' => elgg_echo('save')]);
elgg_set_form_footer($footer);
示例#2
<?php
/**
* Used to show plugin settings for both users and admins.
*
* @package Elgg.Core
* @subpackage Plugins
*/
$plugin = elgg_extract('entity', $vars);
$plugin_id = $plugin->getID();
$user_guid = elgg_extract('user_guid', $vars, elgg_get_logged_in_user_guid());
// Do we want to show admin settings or user settings
$type = elgg_extract('type', $vars, '');
if ($type != 'user') {
$type = '';
}
if (elgg_view_exists("plugins/{$plugin_id}/{$type}settings")) {
echo elgg_view("plugins/{$plugin_id}/{$type}settings", $vars);
}
echo elgg_view_field(['#type' => 'hidden', 'name' => 'plugin_id', 'value' => $plugin_id]);
echo elgg_view_field(['#type' => 'hidden', 'name' => 'user_guid', 'value' => $user_guid]);
$footer = elgg_view_field(['#type' => 'submit', 'value' => elgg_echo('save')]);
elgg_set_form_footer($footer);
示例#3
/**
* Widget edit num_display
*
* @uses $vars['entity'] ElggWidget
* @uses $vars['name'] (optional) The name of the attribute, defaults to 'num_display'
* @uses $vars['default'] (optional) The default value if no value is set, defaults to first option
*/
$widget = elgg_extract('entity', $vars);
if (!$widget instanceof \ElggWidget) {
return;
}
unset($vars['widget']);
$name = elgg_extract('name', $vars, 'num_display');
$vars['name'] = "params[{$name}]";
if (!isset($vars['label'])) {
$vars['label'] = elgg_echo('widget:numbertodisplay');
}
$vars['#label'] = $vars['label'];
unset($vars['label']);
if (!isset($vars['options'])) {
$vars['options'] = [5, 8, 10, 12, 15, 20];
}
$value = sanitize_int($widget->{$name}, false);
if (!$value) {
$value = elgg_extract('default', $vars, $vars['options'][0]);
}
$vars['value'] = $value;
$vars['#type'] = 'select';
echo elgg_view_field($vars);
我被问过这个问题约50次。所以我想我会在这里回答,希望如果其他人最近升级了Elgg,这可能会有所帮助。