【问题标题】:Concrete5 Dynamic select list on user account / add user pageConcrete5 用户帐户/添加用户页面上的动态选择列表
【发布时间】:2017-05-05 04:01:35
【问题描述】:

我想在用户帐户页面上添加表单选择输入/添加带有选项/值动态列表的用户页面。

我知道如何从数据库表中获取动态列表并为选择选项创建动态列表。

echo $form->select('clientsID', $indexed_array, '0');

问题:在哪里以及如何将其添加到帐户/添加用户页面并将其保存到用户表?

【问题讨论】:

    标签: concrete5 concrete5-5.7


    【解决方案1】:

    如果我理解你的话,你需要一个用户属性。它将自动保存在UserInfo 中,如果您正确设置选项,它将显示在用户帐户页面/添加用户页面上。

    请注意,以下所有代码都应该放在/application/controllers 的控制器文件中,或者更好地放在包中。如何创建一个包是有据可查的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
    );
    

    使用的类:

    use \Concrete\Core\Attribute\Type as AttributeType;
    use UserAttributeKey;
    use Concrete\Attribute\Select\Option;
    

    定义属性类型:

    $attrSelect = AttributeType::getByHandle('select');
    

    检查属性是否已经存在,如果不存在,则创建它:

    $mySelect = UserAttributeKey::getByHandle($selectArgs['akHandle'])
    
    if(!is_object($mySelect)) {
        UserAttributeKey::add($attrSelect, $selectArgs);
        $mySelect = UserKey::getByHandle($args_address['akHandle']);
    }
    

    最后将选项填入select:

    foreach($options as $value) {
        Option::add($mySelect, t($value));        
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多