Yii2不起作用yii2-poll-widget

时间:2016-08-22 14:10:25

标签: yii2 widget polling

我在我的页面上使用yii2-poll-widget。 我安装了它:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" tools:node="remove" />

写在我的页面上:

php composer.phar require "pollext/poll":"dev-master"

但我收到错误: 未知属性 - yii \ base \ UnknownPropertyException 设置未知属性:pollext \ poll \ Poll :: pollStatus

如何解决我的问题?

1 个答案:

答案 0 :(得分:1)

推荐pollext/poll,因为它的核心代码中包含多个错误,例如缺少)undefined index。我们(我和另外两个人)试图手动修复其核心文件中的错误(我知道我们不应该这样做,因为它是一个小部件,坐在供应商目录中,但至少我们可以看到如果它完全有效)

您可以尝试在下面使用此代码(我们添加/修改的内容并不多,我们在改进设计和功能方面做得更多,但仍然不够好,不值得继续)

<?php
    use yii\helpers\Html;
    use yii\widgets\ActiveForm;
    use pollext\poll\AjaxSubmitButton;
    use yii\helpers\Url;
?>

<style>
    .poll{
        display: inline-block;
        margin-top: 10px;
        margin-bottom: 10px;
        background: #ffffff;
    }

    .poll label{
        width: 100%;
        font-size: 10pt;
        font-weight: bold;
        display: block;
        color: #464646;
    }

    .poll label:hover{
        cursor: pointer;
    }

    .poll button[type="submit"]{
        font-weight: bold;
        font-size: 10pt;
        margin-top: 10px;
        color: #4682B4;
    }

    .poll-option-name{
        font-weight: bold;
        font-size: 10pt;
        color: #464646;
    }
    .per_container{
        font-weight: bold;
        font-size: 10pt;
        color: #464646;
        padding: 0; 
        margin: 0;
        max-width: 50px;
    }

    .support_forms button[type="submit"]{
        border: none;
        font-weight: normal;
        color: #4682B4;
        margin-left: 0;
        padding: 0;
        background: #ffffff;

    }
    .support_forms button[type="submit"]:hover{
        text-decoration: underline;
    }
    .support_forms button[type="submit"]:focus{
        outline: none;
        border: none;
    }
    .support_forms{
        margin-top: 0;
    }

</style>
<div class="poll" style="width:<?php echo $params['maxLineWidth']+55;?>px;" >
<?php  echo "<div style=\"max-width:".$params['maxLineWidth']."px; word-wrap: break-word; margin-bottom: 10px; font-size:12pt; font-weight:bold;\">".$pollData['poll_name']."</div>";?>
<?php $pullName = (isset($_POST['nameOfPoll'])) ? $_POST['nameOfPoll'] : '';?>
<?php if((Yii::$app->user->getId()==null && $_POST['pollStatus']!='show' && $isVote == false ) || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='vote'&& $_POST['pollStatus']!='show' && Yii::$app->user->getId()==null)){
    echo "Sign in to vote";
}?>
    <?php if(($isVote == false && Yii::$app->user->getId()!=null && !empty($_POST['pollStatus']) && $_POST['pollStatus'] !='show') || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='vote'&& $_POST['pollStatus']!='show' && Yii::$app->user->getId()!=null)){?>

                <?php echo Html::beginForm('#', 'post', ['class'=>'uk-width-medium-1-1 uk-form uk-form-horizontal']); ?>

                <?php echo Html::activeRadioList($model,'voice',$answers); ?>
                <input type="hidden" name="poll_name" value="<?=$pollData['poll_name']?>"/>
                <?php AjaxSubmitButton::begin([
                    'label' => 'Vote',
                    'ajaxOptions' => [
                        'type'=>'POST',
                        'url'=>'#',
                        'success' => new \yii\web\JsExpression('function(data){
                            $("body").html(data);
                            }'),
                    ],
                    'options' => ['class' => 'customclass', 'type' => 'submit'],
                    ]);
                    AjaxSubmitButton::end();
                ?>


                <?php echo Html::endForm(); 
            }

    ?>
    <?php if (($isVote == false && !empty($_POST['pollStatus']) && $_POST['pollStatus'] !='show') || (Yii::$app->user->getId()==null && $_POST['pollStatus']!='show') || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='vote'&& $_POST['pollStatus']!='show')){?>
   <form method="POST" action="" class="support_forms">
   <input type="hidden" name="nameOfPoll" value="<?=$pollData['poll_name']?>"/>
   <input type="hidden" name="pollStatus" value="show"/>
     <?php AjaxSubmitButton::begin([
                    'label' => 'Show results',
                    'ajaxOptions' => [
                        'type'=>'POST',
                        'url'=>'#',
                        'success' => new \yii\web\JsExpression('function(data){
                            $("body").html(data);
                            }'),
                    ],
                    'options' => ['class' => 'customclass', 'type' => 'submit'],
                    ]);
                    AjaxSubmitButton::end();
                ?>
   </form>
    <?php }?>
    <?php if($isVote == true || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='show') ){?> 
        <?php 
            for($i = 0; $i<count($answersData); $i++){ 
                $voicesPer = 0;
                if($sumOfVoices ==0){
                    $voicesPer = 0;
                }else{
                    $voicesPer = round($answersData[$i]['value']/$sumOfVoices, 4);
                }

                $lineWidth = $params['maxLineWidth']*$voicesPer;     
        ?>

            <div class="single-line" style="margin-bottom: 10px; ">
                <?php echo "<div class=\"poll-option-name\">".$answersData[$i]['answers'].": ".$answersData[$i]['value']."</div>"; ?>
                <div  style="width: <?php echo $params['maxLineWidth']; ?>px;  height: <?php echo $params['linesHeight']; ?>px; background-color: <?php echo $params['backgroundLinesColor']; ?>; ">
                    <div style="width: <?php echo $lineWidth;?>px; height: <?php echo $params['linesHeight'] ?>px; background-color: <?php echo $params['linesColor']; ?>;">
                    <div class="per_container" style="display: block; line-height:<?php echo $params['linesHeight'] ?>px;  height: <?php echo $params['linesHeight'] ?>px;  
                    position: relative; left:<?php echo $params['maxLineWidth']+5; ?>px; margin: 0;"><?php echo ($voicesPer*100)."%"?></div>
                    </div>

                </div>
            </div>
        <?php }?>
    <?php }?>
    <?php if ($isVote == false && !empty($_POST['pollStatus']) && $_POST['pollStatus'] == 'show'){?>
    <form method="POST" action="" class="support_forms" style="margin-top: -10px;">
   <input type="hidden" name="nameOfPoll" value="<?=$pollData['poll_name']?>"/>
   <input type="hidden" name="pollStatus" value="vote"/>
     <?php AjaxSubmitButton::begin([
                    'label' => 'Vote',
                    'ajaxOptions' => [
                        'type'=>'POST',
                        'url'=>'#',
                        'success' => new \yii\web\JsExpression('function(data){
                            $("body").html(data);
                            }'),
                    ],
                    'options' => ['class' => 'customclass', 'type' => 'submit'],
                    ]);
                    AjaxSubmitButton::end();
                ?>
     <?php }?>
   </form>
</div>

此修改后来自pollext/views/index.php文件。如果你想知道它是什么样子:

enter image description here

上方是对尚未投票的人的观点,下面是已经投票的人的观点。