lslsoft / yii2-poll
yii2 的投票小部件
dev-master
2017-01-25 22:35 UTC
This package is not auto-updated.
Last update: 2024-09-23 14:27:35 UTC
README
Yii2-poll 小部件
这是一个简单的 yii2 框架投票小部件。您可以同时使用单选和多选题。
安装
可以使用 composer 安装 Yii2-poll。运行以下命令以下载和安装 yii2-poll
composer require lslsoft/yii2-poll
或者在您的项目的 composer.json 文件的 require 部分添加以下内容
"lslsoft/yii2-poll" : "dev-master"
迁移
迁移文件位于文件夹中
lslsoft/yii2-poll/migrations/create
负责创建所需表和关系的文件
lslsoft/yii2-poll/migrations/create
负责插入一些示例数据的文件
要应用迁移,请将以下内容添加到您的配置文件中
'migrate-lslsoft-create' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations/create', 'migrationTable' => 'migration_lslsoft_create', ],
运行以下命令以应用迁移
php yii migrate-lslsoft-create
用于创建所需表和关系
用于插入一些示例数据
'migrate-lslsoft-insert' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations/insert', 'migrationTable' => 'migration_lslsoft_insert', ],
运行以下命令以应用迁移
php yii migrate-lslsoft-insert
###本地化
您应该在您的配置文件中添加以下内容
'i18n' => [ 'translations' => [ 'sourceLanguage' => 'en-En',
'polls*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@yii/vendor/lslsoft/poll/messages',
],
],
],
扩展的基本语言 - 英语 在文件夹 lslsoft/yii2-poll/migrations/messages 中,您将找到俄语和中文文件夹
###使用方法
use lslsoft\poll\Poll; <?= Poll::widget(); ?>
不传递任何参数时将选择第一个投票,
date_beg < today < date_end;
<?= Poll::widget([ 'idPoll' => 1, ] ); ?>
将使用 id 为 1 的 polls 表中的投票;
默认情况下,结果将显示为简单的柱状图
<?= Poll::widget([ 'idPoll' => 1, 'resultView'=>'table' ] ); ?>
将以 GridView 的形式显示结果;
表格
TABLE `polls` ( `id` int(11) NOT NULL COMMENT '№ poll', `question` text NOT NULL COMMENT 'Question', //text of the poll's question `date_beg` date NOT NULL COMMENT 'Date begin',//Date when poll should start `date_end` date NOT NULL COMMENT 'Date end', //Date when poll should end `allow_multiple` tinyint(4) NOT NULL COMMENT 'Multiple answer', //Define type of poll - with only one possible answer or not `is_random` tinyint(4) NOT NULL COMMENT 'Random order', //if true - display answers in random order `anonymous` tinyint(4) NOT NULL COMMENT 'Anonymous answers',//if true - user can vote without sign up `show_vote` int(11) NOT NULL COMMENT 'Show number of votes' //if true - the results will be shown after sending vote ) ENGINE=InnoDB DEFAULT CHARSET=;
CREATE TABLE `polls_answers` ( `id` int(11) NOT NULL COMMENT '№ answer', `id_poll` int(11) DEFAULT NULL COMMENT '№ poll', `answer` text NOT NULL COMMENT 'answer' ) ENGINE=InnoDB;
CREATE TABLE `polls_result` ( `num` int(11) NOT NULL DEFAULT '0' COMMENT 'Number of the voting', `id_poll` int(11) NOT NULL COMMENT '№ of poll', `id_answer` int(11) NOT NULL COMMENT '№ of answer', `id_user` int(11) NOT NULL, `id` int(11) NOT NULL, `create_at` datetime NOT NULL, `update_at` datetime NOT NULL, `ip` varchar(20) NOT NULL, `host` varchar(20) DEFAULT NULL ) ENGINE=InnoDB;
作者
- Leonid Lyalin
许可
此项目受 BSD-3-Clause 许可协议的许可
致谢
- 感谢所有 Yii 框架团队带来的灵感,并特别感谢 Alexander Makarov (@samdark)
- 感谢 @Insolita 的 magic yii2-migrik