Multiple Options Attribute

Permalink
Hey!

Just curious if anyone else has figured this out yet or ran into this problem. I have a custom attribute that will allow multiple options to be chosen. When I do this:

$event_levels = $ep->getAttribute('pb_levels');


And just echo it out, it merges all the chosen attributes together. I noticed it's not in an array. I tried doing a search for a \n, but found none. Any one else know how it's put together? It can't just be in the DB as "option1 option2". Or is it? I couldn't find it.

Thanks!

rainmaker
 
adajad replied on at Permalink Reply
adajad
I have no idea, but I'm curious as to what it actually say in the db. Did you look?
rainmaker replied on at Permalink Reply
rainmaker
I wasn't able to find it. :(
jshannon replied on at Permalink Reply
jshannon
You sure there are no newlines? I just did the same thing with a multi-select and there were newlines (and I was able to use str_replace() to have commas). Take a look at the HTML source to see newlines.

If not... I know for sure that there are other methods within the attribute controller that can provide a more structured format, but I don't have any example code handy right now.

James
rainmaker replied on at Permalink Reply
rainmaker
Hey James!

Hmmm. I tried to do a search and it wasn't seeing the new line. Here's my code:

$event_levels = $ep->getAttribute('pb_levels');
$event_levels = str_replace('\n', ', ', $event_levels);
echo "<br/>For: ".$event_levels."<br/>";


The end result is no comma and just a space between them.
jshannon replied on at Permalink Best Answer Reply
jshannon
Did you look in the HTML source?

Your code won't work, even if there is a new line. Replace '\n' with"\n".

James
rainmaker replied on at Permalink Reply
rainmaker
Dang! Why was it sensitive to double quotes instead of single quotes?

Thanks for the tip!
jshannon replied on at Permalink Reply
jshannon
Same reason that '$var' wouldn't work -- single quotes are more literal than double quotes. Seehttp://php.net/manual/en/language.types.string.php...

James
rainmaker replied on at Permalink Reply
rainmaker
Huh. Gotcha. Didn't realize that. Thanks~! You're a lifesaver!