define( '_JEXEC', 1 );
defined('_JEXEC') or die('Restricted access');
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();现在,我知道对于Joomla 2.5,我必须使用Jinput而不是JRequest (已弃用),所以:
$jAp = JFactory::getApplication();
$jInput = $jAp->input;如前所述,我正在尝试检索文章id。我尝试了许多实例,但似乎都不起作用。
$id = $jInput->get('id', 0); // doesn't work
$idInt = $jInput->getInt('id',0); //doesn't work还有JRequest...我无法获取当前文章id。
只有当我请求登录用户的数据时,这才起作用,例如:
$user = JFactory::getUser();
echo $user->username; // this works...我错过了什么?我的错在哪里?
非常感谢大家!
发布于 2015-01-27 07:32:51
调试AJAX可能很复杂。我经常发现在我的处理程序中添加一些日志记录很有帮助,例如在代码的开头添加以下内容……
# logging of all hits
$log_file = realpath(dirname(__FILE__)) . '/ajax_debug.log';
$fh = fopen($log_file, 'a') or die();
$log_string = "Backend Hit \n" . date("Y-m-d H:i:s") . "\n";
$log_string .= "POST: " . print_r($_POST, true) . "\n";
$log_string .= "GET: " . print_r($_GET, true) . "\n";
$log_string .= "Hit by: " . $_SERVER['REMOTE_ADDR'] . "\n";
$log_string .= "\n\n\n";
fwrite($fh, $log_string);
fclose($fh); 您没有提到AJAX代码是如何/在哪里实现的。这听起来像是Joomla的一个实现。如果它是完全独立的,我倾向于将其放在插件中,尽管模块或组件AJAX处理程序在Joomla中也可以很好地工作。在https://docs.joomla.org/Using_Joomla_Ajax_Interface上有一些很好的文档和代码
https://stackoverflow.com/questions/18210237
复制相似问题