How to get App Title into PHP variable?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

How to get App Title into PHP variable?

Post by onoehring » 2019-11-17 09:19

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 2272 times
In this case I want to receive "Demo" as answer.

Olaf

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: How to get App Title into PHP variable?

Post by pbottcher » 2019-11-18 21:14

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: How to get App Title into PHP variable?

Post by onoehring » 2019-11-19 06:01

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: How to get App Title into PHP variable?

Post by pbottcher » 2019-11-19 18:49

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply