私のJoomla2.5.xサイトに、ユーザーがメールとアドレスを入力するメールフォームを含むFancyboxウィンドウを開くリンクを追加したいと思います。送信時に、プラグインはメールを検証して正しい受信者に送信します。
私はプラグインを作成しましたが、問題に遭遇しました。Ajaxにdbスタッフを実行してメールを送信しているphpスクリプトを呼び出す方法。
次のURLを使用する場合:
$.ajax({
type: 'POST',
url: ''/my_site/plugins/content/my_plugin/sendmessage.php',
...
phpスクリプトはJoomlaリファレンスから外れています。次の理由で終了します。
defined('_JEXEC') or die();
そして、Joomla関数は機能していません。これには、phpスクリプトに次のスタッフを追加するなどの回避策があります。
<?php
define( '_JEXEC', 1 );
// JPATH_BASE should point to Joomla!'s root directory
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/' ) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$user =& JFactory::getUser();
$session =& JFactory::getSession();
?>
しかし、この回避策のセキュリティについてはよくわかりません。そして、私はクリーンなソリューションを好みます。私はたくさん検索しましたが、正しい方法はphp関数を作成し、それをコントローラーに追加して、次の方法でAjaxから呼び出すことであることがわかりました。
$.ajax({
type: 'POST',
url: 'index.php?option=com_mycomponent&format=raw&task=mytask';
...
But is this way is possible only for a Component ? What I need is a Plugin. How can I run a simple ajax call to a php function/script in a Plugin ? Any help will be appreciated, I am looking for a solution for quit some time.