2016-08-22 63 views
1

私のページにyii2-poll-widgetを使用しています。 私はそれをインストール:Yii2が動作しないyii2-poll-widget

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

しかし、私はエラーを取得:

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

そして、私のページに書き 不明なプロパティ - 未知のプロパティを設定するのYii \ベースの\ UnknownPropertyException :pollext \ポーリング\世論調査を:: pollStatus

問題をどのように解決できますか?

+0

こんにちは。これまたは任意の答えがあなたの質問を解決した場合は、チェックマークをクリックしてそれを受け入れることを検討してください。これは、あなたが解決策を見つけ出し、回答者とあなた自身の両方に評判を与えていることを広範なコミュニティに示します。しかし、これを行う義務はありません。 –

答えて

1

それはそのコアコードで複数のエラーが含まれているので、私はは)またはundefined indexを逃すように、pollext/pollをお勧めしません。私たち(私と2人以上)は、コアファイルのエラーを手で修正しようとしました(ベンダのディレクトリにあるウィジェットではありませんが、少なくともそれが動作するかどうかはわかります)

あなたはの下にこのコードを使用しようとすることができます(私たちは修正/追加することはあまりありませんが、我々はデザインと機能性を向上させるために、よりをしましたが、まだ継続する価値がない、十分ではありませんでした)

<?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

アッパーにはまだ投票しなかった人のための図であり、下記すでに投票していた人のための図です。

関連する問題