6 years ago

I am trying to do the following query within a select dynamic field:

SELECT refresher_period as value, refresher_period as text
FROM #__cck_store_join_seb_site_training
WHERE site_id=$site->id
AND course_id=$config['pk']

But I don't seem to be able to access the $config variable? I can access the $uri variable it seems, but this only works to retrieve the value when displaying/editing the form, and not when trying to use the field in a list and search, but I need to access it in both circumstances.

Get a VIP membership
6 years ago
Level 1

I've just looked at the code here. It seems I can use $uri, $context, $user and $site, as well as any J(STRING). Are there any plans to expand this to make $fields and $config available also?

4229 Posts
6 years ago
Level 2

In forms field don't have any values so this doe not make sense, fields become values only after form is saved.

6 years ago
Level 3

Thanks for the info.

I added the following code to the replaceLive function to make $config accessible, but it doesn't appear to be working as expected in the list/search view?

if ( $str != '' && strpos( $str, '$config' ) !== false ) {
  $matches     =   '';
  $search       =   '#\$config\[\'([a-zA-Z0-9_]*)\'\]#';
  preg_match_all( $search, $str, $matches );
  if ( count( $matches[1] ) ) {
    foreach ( $matches[1] as $k=>$v ) {
      $v2     =   ( isset( $config[$v] ) ) ? $config[$v] : '';
      $str   =   str_replace( $matches[0][$k], $v2, $str );

 When I do a dump($str); it seems to be replacing with the correct values, however, e.g.:

SELECT refresher_period as value, refresher_period as text
FROM #__cck_store_join_seb_site_training
WHERE site_id=505
AND course_id=1426 ORDER BY text

Any thoughts?

6 years ago
Level 4

This was due to the field I was using not having a storage location in the database. I managed to work around this by using a join and query in the search and a free text field to retrieve the variable from the search in the search form. Thanks to Olivier Nolbert for the direction on this.

6 years ago
Level 5

I have created a PR with the changes mentioned above here.

1283 Posts
5 years ago
Level 6

Very Nice!

Get a VIP membership