Download the PHP package flsouto/htchoice without Composer

On this page you can find all versions of the php package flsouto/htchoice. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package htchoice

HtChoice

This library can be extended to easily implement widgets that are based on choice. It is not tied to any specific html element and does not define if the user is supposed to choose only one option or multiple options. This is up to your implementation.

Notice: a lot of functionality is already inherited from base abstract classes. So I highly recommend reading these other materials before you start developing with this library:

Installation

Use composer:

Usage

For demonstrating how one would extend this abstract class to implement his own choice type of widget, I have prepared a SimpleChoice class which provides a text-based list of options and an input field where the user is supposed to type in the value of the desired option. Of course in the real world this would be useless since better control elements such as select, radio buttons and checkboxes already exist for that. However this simplified version will be good for showing how custom choice elements can be implemented if you don't like sticking to the standard ones. So here is the implementation of our SimpleChoice class:

Setting the array of options

In order to feed the choice widget with options for the user to choose we must use the options method which accepts an associative array:

Outputs:

Selecting an option

In the next example we want the third option (i.e. the "Fall" season) to be marked as selected:

Outputs:

Readonly mode

We can use the inherited readonly setter to tell the widget we don't want users interacting with it:

Outputs:

Options as Numeric Arrays

Besides associative arrays, the options method accepts numeric arrays. In this case each option's value will be the same as its own label:

Outputs:

Options as Datasets

Usually you will be fetching options from the database and these will come in the form of rows, also known as a dataset structure. The options setter understands that as well:

Outputs:

Notice: the column names don't need to be id and name. They can be anything as long as they occur in the first and second positions of each row. In other words, the first column will always be the value, and the second column will always be the label.

Options as Array of Objects

This is the same as passing a dataset, only that each row is an object instead of an array:

Outputs:

Options as Tuples

The options also accepts an array of tuples in the form: [value1, label1], [value2,label2], and so on...

Outputs:

Lazy Loaded Options

Last but not least, you can pass a function to the options method for returning the options only just before the widget is rendered. This is ideal, for instance, if you are fetching the options from the database:

Outputs:

Notice: the value returned by the lazy loader can be anything supported by the options method: associative arrays, numeric arrays, array of tuples, and even another function, as you can see in the example below:

Outputs:


All versions of htchoice with dependencies

PHP Build Version
Package Version
Requires flsouto/htwidget Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package flsouto/htchoice contains the following files

Loading the files please wait ....