flsouto/htradios 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

flsouto/htradios

Composer 安装命令:

composer require flsouto/htradios

包简介

Generates radio buttons for choosing a single option.

README 文档

README

This library can be used to generate radio buttons in an easy way. I recommend you take a look at the documentation of its parent classes in order to grasp all the inherited functionality:

Installation

Via composer:

composer require flsouto/htradios

Usage

In the following example we generate a choice list with three options.

<?php
require_once('vendor/autoload.php');
use FlSouto\HtRadios;

$select = new HtRadios("id_category");
$select->options([1=>'Category1',2=>'Category2',3=>'Category3']);

echo $select;

Outputs:

<div class="widget 58c445e037fa2" style="display:block">
 <label>
 <input type="radio" name="id_category" value="1" />Category1</label>
 <br />
 <label>
 <input type="radio" name="id_category" value="2" />Category2</label>
 <br />
 <label>
 <input type="radio" name="id_category" value="3" />Category3</label>
 <br />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

Notice: the options method also accepts other formats besides an associative array. Take a look at the documentation of the HtChoice class in order to learn more.

Changing the separator

By default, the separator used to separate the options is a <br/> element, that is, a line break. But you can change that by using the separator method. In the example below we change the separator to be two spaces so that the options are displayed horizontally:

<?php
require_once('vendor/autoload.php');
use FlSouto\HtRadios;

$select = new HtRadios("id_category");
$select->options([1=>'Category1',2=>'Category2',3=>'Category3'])
	->separator("&nbsp;&nbsp;");

echo $select;

Outputs:

<div class="widget 58c445e039f00" style="display:block">
 <label>
 <input type="radio" name="id_category" value="1" />Category1</label>
 &nbsp;&nbsp;
 <label>
 <input type="radio" name="id_category" value="2" />Category2</label>
 &nbsp;&nbsp;
 <label>
 <input type="radio" name="id_category" value="3" />Category3</label>
 &nbsp;&nbsp;
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

Selecting an option

If you have read the documentation of the HtField and the HtWidget parent classes you already know that you are supposed to use the context method in order to set the value of a field/widget:

<?php
require_once('vendor/autoload.php');
use FlSouto\HtRadios;

$select = new HtRadios('id_category');
$select->options([1=>'Category1',2=>'Category2',3=>'Category3']);
$select->context(['id_category'=>2]);

echo $select;

Outputs:

<div class="widget 58c445e03a67b" style="display:block">
 <label>
 <input type="radio" name="id_category" value="1" />Category1</label>
 <br />
 <label>
 <input type="radio" name="id_category" value="2" checked="checked" />Category2</label>
 <br />
 <label>
 <input type="radio" name="id_category" value="3" />Category3</label>
 <br />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固