2011-05-05 148 views
1

http://docs.joomla.org/Adding_a_multiple_item_select_list_parameter_type的Joomla 1.6升级1.5

为一个自定义的参数类型添加到您的模块和方法的文档那是,如果你看一下底轮有这样一行:保存参数值到数据库

请有人告诉我,如果有任何关于如何在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'] 
     ); 

    } 

回答

3

结帐this,如何JParams转换为JForm

编辑:

我检查了论坛,发现使用的是

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

但在JHTML中,您传递了文本和val的标识和标题UE场,

使用

// 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']; 
    } 
+0

它有趣我已经看过这个文件了,不过还有的getInput()需要如何实现没有真实的例子:“替代函数fetchElement($名称,$值,&$ node,$ control_name)和保护函数getInput()“ – 2011-05-06 07:22:57

+0

没有人可以帮我吗? – 2011-05-09 12:03:58

+0

您是否尝试过1.6中的1.5元素代码。我没有任何问题。 – Gaurav 2011-05-09 12:23:19