Storing array in $this->course variable.

Storing array in $this->course variable.

by Dale Davies -
Number of replies: 2
Hi, my apologies if this makes no sense, I find these things difficult to explain!

I'm creating a block with an instance config page, on this page I'd like to give the user a list of teachers to chose from, where they can select multiple values from this list.

However I have tried to store this array of values in $this->config->teacherslist but have found I cannot store an array here.

How would I be best storing the multiple values in the block's instance config?

Many thanks,
Dale.
Average of ratings: -
In reply to Dale Davies

Re: Storing array in $this->course variable.

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Why can't you store an array there? I would expect that to work. $this->config->teacherslist = array('fred', 'jane');
In reply to Tim Hunt

Re: Storing array in $this->course variable.

by Dale Davies -
To be honest I dont know exactly why I cant store an array in there, I thought it was something about the variable being stored in the database meaning it cant be stored as an array. Or is that complete nonsense?

It definately doesnt work, I know that. After the instance config page is saved, I cant retreive all the values, only the last value. As in, the last value seems to be stored as a string.

Ive come up with a way around it however, using javascript to concatenate all the values into a comma delimited string before the form is posted. Then use explode() to put them back into an array when I need them.