PHP Variable in Placeholder?

hominid4

Member
Sorry, seems like I seen the answer to this years back but can't find it. Is it possible to have a variable within a placeholder?

$foo = 'bar';
$placeholder = '{'.$foo.'_table___element}';
Instead of: '{bar_table___element}';


A very simplified example of what I'm trying to achieve is, to dynamically pull a specified component of the URL path and dynamically populate the variable within the placeholder, such as:

My URLs (after "/classes/" contains the prefix of each respective table):
my-domain/classes/school_one
my-domain/classes/school_two

// Get school_one or school_two from current URL and use as the table prefix
$currentUri = JUri::current();
$tblPrefix = explode('/',$currentUri)[4];

$elSchoolClassName = '{'.$tblPrefix.'_classes___class_name}';


To return either one of the below placeholders based on the current URL:

$elSchoolClassName = '{school_one_classes___class_name}';
or
$elSchoolClassName = '{school_two_classes___class_name}';


I've been trying different tests with no luck and assume it's not possible (due to the code's firing order?) but thought I'd ask just to confirm.

Thanks!
J!: 3.9.28
Fabrik: Latest GitHub
 
Last edited:
PHP:
$tbl_name = 'tbl_name';
$el = '{' . $tbl_name . '___el_name}';
return $el;
This worked for me in calc element.
 
Thanks, I think in my case by the time I'm pulling the variable from the URL it's too late, the placeholders have already been evaluated and all I'm doing at that point is creating a "dead" string variable.
 
You may run it through parseMessage... yourself
$w = new FabrikWorker;
$el = $w->parseMessageForPlaceHolder($el, $data, true, true);//at least this is doing in form view in a calc
or fetch the element data with one of these
http://fabrikar.com/forums/index.php?wiki/php-form-plugin/#accessing-form-data

Ah, keep in mind that all element placeholders and also the form data can only show data of your form (which belongs to a list). So you can access any {school_one_classes___xxx} only in list/form/DB-table `school_one_classes` (or some joined tables).

If you want to access different DB tables from a form you have to do it with DB queries.
 
Last edited:
Oh nice, thanks troester, using pareMessage worked perfectly; and good to know for future reference.

Sorry, I could of explained a little further how I was utilizing this. I've created around 30 different "programs" for a school, each having a separate "Class" list per program, and Attendance is kept for each class per program. I've created an "Attendance" calc element column that shows within each of the Classes lists that checks if attendance was added for each of classes' rows. Instead of creating a standalone Attendance calc element per program's class form (30 of them) where I have to manually enter each respective table prefix per calc element and maintain those with future enhancements, I was shooting to create one parent calc element, since the code is identical except for the table prefix, and the rest being the child elements so that I can just maintain that one and the table prefix dynamically pulled in based on the URL.

Thanks again, I'm good to go!
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top