2016-08-22 75 views
1

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

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

而且我的网页上写:

<?php 
use pollext\poll\Poll;?> 
<?php 
     echo Poll::widget([ 
      'pollName'=>'Do you like PHP?', 
      'answerOptions'=> 
       [ 
        'Yes', 
        'No', 
       ], 
     ]); 
    ?> 

,但我得到的错误: 财产来源不明 - 警予\基地\ UnknownPropertyException 设置未知属性:pollext \调查\投票:: pollStatus

我该如何解决我的问题?

+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

上是谁还不投票人的图,下面是谁已经投了一个人一个看法。