1
我想在用户帐户页面上添加一个表格选择输入/添加具有动态选项/值列表的用户页面。Concrete5用户帐户/添加用户页面上的动态选择列表
我知道如何从数据库表中获取动态列表并为选择选项创建一个动态列表。
echo $form->select('clientsID', $indexed_array, '0');
问题:在何处以及如何将其添加到帐户/添加用户页面并将其保存到用户表中?
我想在用户帐户页面上添加一个表格选择输入/添加具有动态选项/值列表的用户页面。Concrete5用户帐户/添加用户页面上的动态选择列表
我知道如何从数据库表中获取动态列表并为选择选项创建一个动态列表。
echo $form->select('clientsID', $indexed_array, '0');
问题:在何处以及如何将其添加到帐户/添加用户页面并将其保存到用户表中?
如果我很了解你,你需要一个用户属性。它将自动保存在UserInfo
中,如果您正确设置选项,它将显示在用户帐户页面/添加用户页面上。
请注意,以下所有代码都应放在/application/controllers
的Controller文件中,或者在软件包内更好。如何创建一个软件包有详细的文档记录here。这样你的网站就可以无任何问题地更新。
$options = array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz'
);
属性参数:
$selectArgs = array(
'akHandle' => 'my_select',
'akName' => t('my Select'), // t() is for translation
'uakProfileDisplay' => true, // Will be displayed on the Users Profile page
'uakMemberListDisplay' => true, // Will be displayed on the dashboard members page
'uakProfileEdit' => true, // A memeber is able to edit the attribute
'uakProfileEditRequired' => true, // The attribute MUST be filled with a value
'uakRegisterEdit' => true, // Will be displayed on the Register Page
'uakRegisterEditRequired' => true, // The attribute MUST be filled with a value upon registration
'akIsSearchableIndexed' => true, // The attribute will be indexed (searchable)
'akSelectAllowOtherValues' => false, // A user may add/remove other options to the select attribute
'akSelectOptionDisplayOrder' => 'alpha_asc', // the display order
'akIsSearchable' => true // one can search by these options
);
您与从DB表或动态值其他来源关联数组在用户属性(在这种情况下,下拉)来填充
使用的类别:
use \Concrete\Core\Attribute\Type as AttributeType;
use UserAttributeKey;
use Concrete\Attribute\Select\Option;
Defi NE的属性类型:
$attrSelect = AttributeType::getByHandle('select');
检查,如果属性已经存在,如果没有,创建它:
$mySelect = UserAttributeKey::getByHandle($selectArgs['akHandle'])
if(!is_object($mySelect)) {
UserAttributeKey::add($attrSelect, $selectArgs);
$mySelect = UserKey::getByHandle($args_address['akHandle']);
}
最后填充选项加入到选择:
foreach($options as $value) {
Option::add($mySelect, t($value));
}