Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to pass a variable set in Controller to Select Helper “value”?

I have something like this in my Controller:

$this->view->userTagsComma = ($skills[0] == 'No Skills Set')?'':'"' . implode('", "', $skills) . '"';

And this generates something like "Cooking", "Swimming" when I echo this in View.

And in my View I have:

<?php echo Phalcon\Tag::select(array('user-skills-input', 
                                      TagsStandard::find("status = 1"), 
                                      "using" => array("name", "name"),
                                      "class" => "select-chosen",
                                      "type" => "text",
                                      "data-role" => "tagsinput",
                                      "value" => [],
                                      "multiple" => "multiple"
                                                        )); ?>

I want to pass $userTagsComma into [] in my select helper so how can I do it? I tried doing "view" => [$userTagsComma] in the select helper but it does not work.

Update: I tried putting in "value" => ["Cooking", "Swimming"], and this works. So not sure why passing in a variable with everything looking the same wouldn't work.

hi,

I think you are putting a string, and not an array.

What about "value" => explode(", ", $userTagsComma) ?

edited Jul '15

Hi,

Thanks for the help in advance. I tried that and it didn't work. When I echo explode(", ", $userTagsComma); it gives me Notice: Array to string conversion

hi,

I think you are putting a string, and not an array.

What about "value" => explode(", ", $userTagsComma) ?



12.6k
Accepted
answer
edited Jul '15

you can't echo an array. Use print_r($userTagsComma) to see the contents of an object/array. As Max said, by using implode you're passing a string instead of an array. How about passing $skills directly?

$this->view->userTagsComma = ($skills[0] == "No Skills Set") ? [] : $skills;

Wow thanks alot. Works perfectly.

you can't echo an array. Use print_r($userTagsComma) to see the contents of an object/array. As Max said, by using implode you're passing a string instead of an array. How about passing $skills directly?

$this->view->userTagsComma = ($skills[0] == "No Skills Set") ? [] : $skills;