Yii2不';t work yii2轮询小部件
我在我的页面上使用yii2 poll小部件。 我安装了它:Yii2不';t work yii2轮询小部件,yii2,widget,polling,Yii2,Widget,Polling,我在我的页面上使用yii2 poll小部件。 我安装了它: php composer.phar require "pollext/poll":"dev-master" 在我的页面上写下: <?php use pollext\poll\Poll;?> <?php echo Poll::widget([ 'pollName'=>'Do you like PHP?', 'answerOptions'=>
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',
],
]);
?>
但我得到了一个错误:
未知属性–yii\base\UnknownPropertyException
设置未知属性:pollext\poll\poll::pollStatus
如何解决我的问题?我不建议这样做,因为它的核心代码中包含多个错误,例如缺少
)
或未定义的索引。我们(我和另外两个人)试图手动修复其核心文件中的错误(我知道我们不应该这样做,因为它是一个小部件,位于供应商目录中,但至少我们可以看到它是否有效)
您可以尝试使用下面的代码(我们添加/修改的代码不多,我们在改进设计和功能方面做了更多,但仍然不够好,不值得继续):
.投票{
显示:内联块;
边缘顶部:10px;
边缘底部:10px;
背景:#ffffff;
}
.投票标签{
宽度:100%;
字号:10pt;
字体大小:粗体;
显示:块;
颜色:#4646;
}
。投票标签:悬停{
光标:指针;
}
.poll按钮[type=“submit”]{
字体大小:粗体;
字号:10pt;
边缘顶部:10px;
颜色:#4682B4;
}
.poll选项名称{
字体大小:粗体;
字号:10pt;
颜色:#4646;
}
.每箱{
字体大小:粗体;
字号:10pt;
颜色:#4646;
填充:0;
保证金:0;
最大宽度:50px;
}
.支持表单按钮[type=“submit”]{
边界:无;
字体大小:正常;
颜色:#4682B4;
左边距:0;
填充:0;
背景:#ffffff;
}
.支持表单按钮[type=“submit”]:悬停{
文字装饰:下划线;
}
.支持表单按钮[type=“submit”]:焦点{
大纲:无;
边界:无;
}
.支持表格{
边际上限:0;
}
你好如果这个或任何答案已经解决了你的问题,请考虑通过点击复选标记接受它。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。不过,没有义务这样做。
<?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>