如何将Controller中的变量集传递给Select Helper“value”?

时间:2015-07-23 01:05:09

标签: phalcon

我的控制器中有这样的东西:

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

当我在View中回显这个时,会产生类似"Cooking", "Swimming"的内容。

在我看来,我有:

<?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"
                                                        )); ?>

我想在我的选择助手中将$userTagsComma传递给[],那该怎么办呢?我尝试在select帮助程序中执行"view" => [$userTagsComma]但它不起作用。

更新:我尝试输入"value" => ["Cooking", "Swimming"],,这很有效。所以不确定为什么传递一个看起来相同的变量是行不通的。

2 个答案:

答案 0 :(得分:0)

试试这个!

$(function () { // equivalent to $(document).ready(function() { 

    // div that holds the game area
    var snakeBoardHolder = $('#snake-board-holder');
    // make it have the same height as width
    snakeBoardHolder.height(snakeBoardHolder.width());

    // draw canvas for the snake to live on
    // http://raphaeljs.com/reference.html#Raphael
    if (!Raphael.svg) throw new Error("Your browser does not support SVG elements! Game won't work.");
    var snakeBoard = Raphael("snake-board-holder", snakeBoardHolder.width(), snakeBoardHolder.height());

    // make the game area (div) have height always equal to width,
    // and make the Raphel object (canvas) inside it have the same dimensions 
    $(window).resize(function () {
        var w = snakeBoardHolder.width();
        snakeBoardHolder.height(w);
        snakeBoard.setSize(w, w);
    });

    // start new snake game
    var SG = new Game(snakeBoard, 16, 16);
    SG.startNew();

});


// define snake object
    function Snake ( )
    {


    }

    // define game object
    function Game ( board, blocksVert, blocksHorz ) 
    {
        //      board: Raphael object that the snake will live on
        // blocksVert: height of the game in blocks
        // blocksHorz: width of the game in blocks 

        var board = this.board;
        var snake; // Snake object on the board
        var openCoords; // coordinates on which the snake is not living at the moment

        function startNew ( ) 
        {
            this.snake = new Snake ();
            this.openCoords = new Array ();
        }
    }

答案 1 :(得分:0)

在Controller $this->view->userTagsComma = ($skills[0] == "No Skills Set") ? [] : $skills;中使用它而不是imploding,因为它已经是一个数组。