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:
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!
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!
I have no idea, but I'm curious as to what it actually say in the db. Did you look?
I wasn't able to find it. :(
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
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
Hey James!
Hmmm. I tried to do a search and it wasn't seeing the new line. Here's my code:
The end result is no comma and just a space between them.
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.
Did you look in the HTML source?
Your code won't work, even if there is a new line. Replace '\n' with"\n".
James
Your code won't work, even if there is a new line. Replace '\n' with"\n".
James
Dang! Why was it sensitive to double quotes instead of single quotes?
Thanks for the tip!
Thanks for the tip!
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
James
Huh. Gotcha. Didn't realize that. Thanks~! You're a lifesaver!