[SOLVED]Code works in blank app but not in grid OnApplicationIni

Hello,

I am currently facing a major problem. I have a grid and linked in IFrame a form for uploading files. With grid OnApplicationIni I need to get Joomla CMS User Name. I managed to do so using a blank application, upload this to my main Joomla installation folder and use Wrapper with CMS. I can echo the Global Var UserName, no problem:


// GET JOOMLA USER NAME
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
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();
$joomla_name = $user->name;
$joomla_email = $user->email;
$joomla_password = $user->password;
$joomla_username = $user->username;

[UserName] = $joomla_username;

When I try to use this with Grid OnApplicationIni, my Scriptcase app just doesn’t do anything. The page is white, no code at all is being executed. I already tried to use a blank app, sc_redirect to my grid…but the Global Var just isn’t working in grid. I will need [UserName] with grid sql as well as form.

@aductom: would you know a work around using PHP Methods maybe? Never worked with those…somehow I need to execute my code in order to get the Global Var, before Grid is performing it’s sql:


SELECT 
    `x`,
    `y`
FROM 
    csv_upload
WHERE
    CreatedUser = '[UserName]'
ORDER BY
    id DESC

I kind of had another problem using the following code with grid OnApplicationIni:

// GET LANGUAGE
$ActiveLanguage = 'english';
[ActiveLanguage] = $ActiveLanguage;

// SET LANGUAGE
if ($ActiveLanguage = 'german'){
sc_set_language('de');
	echo 'is german';
}
elseif ($ActiveLanguage = 'english'){
sc_set_language('en_us');
	echo 'is english';
}
else {
sc_set_language('en_us');
	echo 'no language';
}

Here I get an error message. Some time ago support told me that I have to check my code, but by now I think there is something odd with the execution of codes OnApplicationIni:

Error include() [function.include]: Failed opening ‘/…/_lib/buttons/’ for inclusion (include_path=’.:/usr/local/lib/php’)

I tried to use form as master as well and link a grid IFrame. Same behaviour! This bug is killing my time right now and project is on hold. I opened a ticket as well.

Hello,

Please make sure that the code is properly working on your Blank Application. Also enable debug mode on any application you will use any SQL Statement.

Have you tried to echo [UserName] on any event? The problem may be caused due to you SQL Statement.

Have you tried to run this code on the scriptInit()?

Is the first problem in any way related to the second one?


if ($ActiveLanguage [B]=[/B] 'german')

I guess you just mistyped the statement above, but just in case, notice that you are using = to compare two strings instead of ==.

regards,
Bernhard Bernsmann

I found a nice work around:

I am using a blank application where my code for getting Joomla User Name works and I catch current site language through URL…based on the current Joomla URL I use sc_redir($app, GlobVar=$someval); to navigate to my apps…this finally worked.

Those codes are not related problems. With my second code I tried “=” as well in order to compare the strings. Same error. I can’t really tell the reason for my first code not to work, but maybe the code wasn’t able to get the current User Name, because app was bind into Joomla using the Wrapper. This might be the reason why setting [UserName] global did not work as well. The only way it worked was: sc_redir($app, GlobVar=$someval);

closed

Thank you for feedback…