저는 Joomla에 정말 새로 왔습니다. 1.6 또한 매우 새 것으로 보입니다. 따라서 모듈 백엔드의 모듈 매개 변수 필드에 데이터를 저장하는 데 약간의 문제가 있습니다.아약스를 사용하여 모듈 매개 변수를 저장하는 모듈 개발 문제
좀 더 설명해 드리겠습니다.
저는 Joomla 1.6에서 joomla 모듈을 사용하여 사람들이 구독하기를 원하는 작은 연락처 관리자가 있습니다. 이제 모듈이 만들어지고 모든 것이 잘 작동합니다. 나는 심지어 내 API를 호출하고 필요한 데이터로 드롭 다운 상자를 채우는 모듈 백엔드에서 사용자 정의 필드를 만드는 것이 옳다.
템플릿에 쉽게 액세스 할 수 있도록 모듈 매개 변수로 선택 항목을 저장할 수 있기를 원합니다. 이것에 대한 문서를 찾을 수 없기 때문에이 작업을 수행하기가 매우 어려워 보입니다.
기본적으로 내 프로세스는 다음과 같습니다.
- 나는 joomla의 모듈 관리자 admin으로갑니다.
- 설치된 모듈을 선택하고 을 열어 보겠습니다.
- 드롭 다운 상자에 연락처를 등록 할 수있는 이름 인 목록을 채우려면 코드가 실행됩니다.
- 는 키커를 - 내가 얻을
- 나는 목록의 이름을 선택하고 아약스와 onchange를 Joomla를 DB에 모듈 PARAMS 필드에 요청의 ID 을 저장 수 있도록하려면 onchange 이벤트를 실행하고 포스트 요청으로 스크립트를 실행하지만 POST를 처리하고 DB 인스턴스를 가져 와서 데이터베이스에 대한 작업을 수행 할 수는 없습니다. 설명 그게 전부, 여기에 코드입니다 : 모듈 백엔드에서
사용자 정의 필드
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
jimport('joomla.html.html');
//import the necessary class definition for formfield
jimport('joomla.form.formfield');
// Include API utility file
require_once(dirname(__FILE__) . '/../lib/pmailer_subscription_api.php');
/**
* Defines the JFormFieldLists class for the pMailer subscription module for
* Joomla CMS version 1.6 to get the lists provided the API key.
*
* @category Joomla
* @package Modules
* @copyright 2011 Prefix Technologies Pty (Ltd) (http://www.prefix.co.za/)
* @link http://www.pmailer.co.za/
*/
class JFormFieldLists extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'lists'; //the form field type
/**
* Method to retrieve the lists that resides in your pMailer account using
* the API.
*
* @return array The field option objects.
* @since 1.6
*/
protected function getInput()
{
$document = JFactory::getDocument();
$document->addScript(
JURI::base() . '../modules/mod_pmailer_subscription/lib/'
. 'mod_pmailer_subscription.js'
);
$options = array();
$attr = '';
/*
* Initialize JavaScript field attributes. This is the path to the
* ajax handler that will save your list selection.
*/
$attr .= $this->element['onchange'] = (string)
'onchange="javascript: saveListSelection(\''
. JURI::base()
. '../modules/mod_pmailer_subscription/lib/utils.php'
. '\')"';
// 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']] = $list['list_name'];
}
// The dropdown output
return JHTML::_(
'select.genericlist',
$lists,
'mod_pmailer_lists_box',
trim($attr),
'id',
'title',
$this->value
);
}
}
PARAM
에게 자바 스크립트
을 절약 할 수 유틸리티 파일// Gets called on dropdown change event
function saveListSelection(url)
{
// Ajax code here to save list selection
var x = new Request({
url: url,
method: 'post'
}).send('op=saveList&id=' + $('mod_pmailer_lists_box').get('value'));
}
당신이 나에게 미친 듯이 붙어있는이 방법에 대한 조언을 해주기를 바랍니다. 유일한 제약 조건은 모듈이어야한다는 것입니다. 보스의 명령.
lol 아무도 Joomla를 좋아하지 않으므로 관련이 있습니다;) –