doushi9780 2016-10-04 09:37
浏览 43

PHP在Joomla 3.5中包含后不执行

I have the following code and everytime I try to echo something above my include it doesn't work, seems like the 'include' is breakng my code.

PD:For more information my file is inside /my_main_folder/administrator/components/com_helloworld/

<?php 
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../' ));  

include(JPATH_BASE.'/libraries/loader.php');

$name = "a";
$username = "b";
$password = "jhvv";
$email = "arcghh";

addJoomlaUser($name, $username, $password, $email);

function addJoomlaUser($name, $username, $password, $email) {
    jimport('joomla.user.helper');
    $data = array(
        "name"=>$name,
        "username"=>$username,
        "password"=>$password,
        "password2"=>$password,
        "email"=>$email,
        "block"=>0,
        "groups"=>array("1","2")
    );

    $user = new JUser;
    //Write to database
    if(!$user->bind($data)) {
        throw new Exception("Could not bind data. Error: " . $user->getError());
    }
    if (!$user->save()) {
        throw new Exception("Could not save user. Error: " . $user->getError());
    }

    return $user->id;
}

?>

  • 写回答

2条回答 默认 最新

  • douxingti9307 2016-10-04 09:49
    关注

    you are trying to redefine a constant that is already defined, with:

    define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../' ));  
    

    This is probably what is breaking your code. See Joomla constants

    评论

报告相同问题?

悬赏问题

  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置