Answer the question
In order to leave comments, you need to log in
How to pass parameters to widget?
I have the following widget:
class Polls extends \yii\base\Widget {
public function run() {
$poll = Poll::findOne(20);
$answers = Poll_choice::find()->where('poll_id = 20')->all();
if($poll){
if(!$poll->userCanVote(\Yii::$app->request->userIP)){
$pollVote = new Poll_vote();
if(Poll_choice::issetChoiceInPoll($poll->id, 56)){
$pollVote->poll_id = $poll->id;
$pollVote->choice_id = 56;
$pollVote->user_id = \Yii::$app->user->id;
$pollVote->ip_address = \Yii::$app->request->userIP;
$pollVote->save();
}else
echo "Test";
}
}
return $this->render('poll.twig',[
'question' => $poll,
'answers' => $answers,
]);
}
}
Answer the question
In order to leave comments, you need to log in
Add property to widget like message
class Polls extends \yii\base\Widget {
public $message;
...
}
<?php
use app\components\Polls;
?>
<?= Polls::widget(['message' => ' Yii2.0']) ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question