2016-08-22 62 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

上是誰還不投票人的圖,下面是誰已經投了一個人一個看法。