【问题标题】:Joomla 1.6 Upgrade from 1.5Joomla 1.6 从 1.5 升级
【发布时间】:2011-05-05 14:41:19
【问题描述】:

http://docs.joomla.org/Adding_a_multiple_item_select_list_parameter_type

这就是向模块添加自定义参数类型的方法的文档,如果您查看底部的圆形,则有这一行:将参数值保存到数据库

请有人告诉我是否有任何关于如何在 Joomla 1.6 中执行此操作的文档,因为我在任何地方都找不到它?

我完全理解这是如何工作的,您需要将您的自定义选项(例如:来自多选输入框的列表选择)绑定到父项,以便它能够将选择保存到数据库。

提前谢谢你。

编辑添加的代码

protected function getInput()
    {

        $options = array();
        $attr = '';

        $attr .= ' multiple="multiple"';
        $attr .= ' style="width:220px;height:160px;"';

        // Get the database instance
        $db = JFactory::getDbo();
        // Build the select query
        $query = 'SELECT params FROM jos_modules'
            . ' WHERE module="mod_pmailer_subscription"';
        $db->setQuery($query);
        $params = $db->loadObjectList();

        // Decode the options to get thje api key and url
        $options = json_decode($params[0]->params, true);

        // Create a new API utility class
        $api = new PMailerSubscriptionApiV1_0(
            $options['enterprise_url'],
            $options['pmailer_api_key']
        );

        // Get the lists needed for subscription
        $response = $api->getLists();

        // Make a default entry for the dropdown
        $lists = array('0' => 'Please select a list');

        // Builds the options for the dropdown
        foreach ( $response['data'] as $list )
        {
            $lists[$list['list_id']]['id']    = $list['list_id'];
            $lists[$list['list_id']]['title'] = $list['list_name'];
        }

        // The dropdown output
        return JHTML::_(
            'select.genericlist',
            $lists,
            'jform[params][list_id]',
            trim($attr),
            'id',
            'title',
            $options['list_id']
        );

    }

【问题讨论】:

    标签: php joomla joomla1.6


    【解决方案1】:

    结帐this,如何将 JParams 转换为 JForm

    编辑:

    我查了论坛发现你在用

    // Builds the options for the dropdown
    foreach ( $response['data'] as $list )
    {
       $lists[$list['list_id']] = $list['list_name'];
    }
    

    但在 JHTML 中,您正在为文本和值字段传递 id 和标题,

    使用

        // Builds the options for the dropdown
        foreach ( $response['data'] as $list )
        {
            $lists[$list['list_id']]['id']    = $list['list_id'];
            $lists[$list['list_id']]['title'] = $list['list_name'];
        }
    

    【讨论】:

    • 有趣的是我已经看过这个文档但是没有关于如何实现 getInput() 的真实示例:“替换函数 fetchElement($name, $value, &$node, $ control_name) 和受保护的函数 getInput()"
    • 1.6的1.5元素代码你试过了吗?我这样做没有任何问题。
    • Then you still need to replace the references to $control_name and others in your new JForm field, but at least the bulk of the work has been done automatically 你在说这个吗?父类 JFormField 有一个名为 protected $formControl; 的受保护变量
    • @etbal : 让我知道你到底想做什么?
    • 我已经实现了它,但它仍然没有将选择保存到模块参数字段中。我现在将编辑我的问题并添加代码
    猜你喜欢
    • 1970-01-01
    • 2012-12-12
    • 2013-02-22
    • 2014-03-01
    • 2011-07-02
    • 2011-07-08
    • 1970-01-01
    • 2011-08-12
    • 2011-12-24
    相关资源
    最近更新 更多