LISE and Custom Field from UDT

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

LISE and Custom Field from UDT

Post by clapczyn »

Hi, I'm trying to use the "Custom Field from UDT" fielddef in LISE but I just can't get it to work.

So I've got a UDT that just reads out all directories and files in a given directory:

Code: Select all

if ($fh = opendir('uploads/mydir/')) {
while (false !== ($entry = readdir($fh))) {
  if ($entry != "." && $entry != "..") {
    $files[] = $entry; 
  }
}
closedir($fh);
}
return $files;
this should populate the dropdown but it just doesn't. As far as I understand it the UDT should return an array which it does.

I'm pretty sure I'm missing something really simple, but I just don't see it.
I'm thankful for any help …

Stefan
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE and Custom Field from UDT

Post by velden »

It's not that hard to debug this UDT itself. Did you check the output before using it in LISE?

Code: Select all

if ($fh = opendir('uploads/mydir/')) {
I'd suspect this very first line returns false. Often those relative paths don't work as you don't know the current working directory.
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

Re: LISE and Custom Field from UDT

Post by clapczyn »

nope, UDT works just fine – returns this array:

Array ( [0] => folder_a [1] => folder_b [2] => folder_c [3] => folder_d ) 1
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE and Custom Field from UDT

Post by Jo Morg »

LISE template expects an associative array in order to be able to point to a selected value when it exists. What you can do is change this line:

Code: Select all

/*****/
$files[] = $entry;
/** change to **/
$files[$entry] = $entry;
/*****/
 
Last edited by Jo Morg on Fri Sep 30, 2016 1:19 pm, edited 1 time in total.
Reason: Made a mistake on the code, corrected now...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

Re: LISE and Custom Field from UDT

Post by clapczyn »

Hi,

looks like both answers were correct and I'm an idiot ;D :-X

1. yes, the field requires an associative array as a return value ::)
2. also the filepath was wrong:
I tested the tag in the template where the relative path worked just fine. But when the UDT is called from the field definition it seems the script is included somewhere else ?! the relative path wasn't working anymore so i had to use root-path/my_relative_path to get to where I wanted to be …

anyway, thx a lot for your help and thx for this great module ;)
Locked

Return to “Modules/Add-Ons”