Page 1 of 1

How to get App Title into PHP variable?

Posted: 2019-11-17 09:19
by onoehring
Hi,

is there a way to automatically read the title of the application from ... somewhere? I would not like to set this by hand, as I want to write some reusable code.

What title am I talking about? This:
ec201.png
ec201.png (13.9 KiB) Viewed 3169 times
In this case I want to receive "Demo" as answer.

Olaf

Re: How to get App Title into PHP variable?

Posted: 2019-11-18 21:14
by pbottcher
Hi Olaf,

you can add the following to the hooks/__global.php file (at the top):

Code: Select all

<?php
		$f_array=file("$thisDir/../membership_signup.php");
		$re = "/(?<=['\"\\(])[^\"()\\n']*?(?=[\\)\"'])/m"; 
		foreach ($f_array as $line_num => $line) {

			if (strpos($line,'app_name')) {
				preg_match_all($re, $line, $matches);
				$app_name=$matches[0][0];
				break;
			} 
		}

	function login_ok($memberInfo, &$args){ 
        .....
Now you have the $app_name variable.

Re: How to get App Title into PHP variable?

Posted: 2019-11-19 06:01
by onoehring
Hi pbötcher,

thanks for this code.
I added

Code: Select all

$thisDir = dirname(__FILE__);
after the opening of <?php to set this variable (I guess that was missed). Now, as you have written, I can access $app_name from another file.

Interesting though, that AG defines $app_name in the membership_signup.php file, but not in some application definition file which sets some basic variables, maybe even in the config.php. Wouldn't this be better? Is this woth a feature suggestion/request?

Olaf

Re: How to get App Title into PHP variable?

Posted: 2019-11-19 18:49
by pbottcher
Hi,

thanks for the correction. Indeed, I missed this statement during copy&paste. If you need the variable more often it makes sense to put it as a feature request. So far, I did not need it yet.