1. Go to this page and download the library: Download nickelit/html library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nickelit / html example snippets
use Com\NickelIt\Html\Select\Option\ChildOption;
use Com\NickelIt\Html\Select\Option\ParentOption;
use Com\NickelIt\Html\Select\SelectBuilder;
/*
* SelectBuilder::thisParent(string $select_input_id, array $options)->withChild(string $sub_select_input_id, array $sub_options)...
* ParentOption(string $id, string $title)
* ChildOption(string $direct_parent_id, string $id, string $title)
*
* HTML Helper :
* ->render( string $select_box_name, string $id, array $select_html_attribut = [] );
*
* In Your php script or your controller you access the selected values by "select_box_name". The returned value is the $id of the option.
*/
$selectBuilder = SelectBuilder::thisParent( 'ville_production',
[
new ParentOption( '10', 'Rabat' ),
new ParentOption( '20', 'Salé' ),
new ParentOption( '30', 'Casa' ),
]
)->withChild( 'site_production',
[
new ChildOption( '10', '10', 'Site de Agdal' ),
new ChildOption( '10', '20', 'Site de Rabat ville' ),
new ChildOption( '20', '30', 'Site de Salé Tabrikt' ),
new ChildOption( '30', '40', 'Site de Casa Port' ),
new ChildOption( '30', '50', 'Site de Casa Sidi Momen' ),
new ChildOption( '30', '60', 'Site de Casa Sidi Maarouf' ),
]
)->withChild( 'projet_production',
[
new ChildOption( '10', '10', 'Projet Orange Rabat Agdal' ),
new ChildOption( '20', '20', 'Projet Orange Rabat ville' ),
new ChildOption( '20', '30', 'Projet Axa Assurance Rabat ville' ),
new ChildOption( '30', '40', 'Projet Axa Assurance Salé Tabrikt' ),
new ChildOption( '30', '50', 'Projet Axa Assurance Salé Tabrikt' ),
]
)->withChild( 'equipe_production',
[
new ChildOption( '10', '10', 'Equipe A' ),
new ChildOption( '10', '10', 'Equipe B' ),
new ChildOption( '20', '10', 'Equipe C' ),
new ChildOption( '30', '10', 'Equipe D' ),
]
)->end();
use Com\NickelIt\Html\Select\Option\ChildOption;
use Com\NickelIt\Html\Select\Option\ParentOption;
use Com\NickelIt\Html\Select\SelectBuilder;
_production";
$projetUrl = $baseUrl . "/api/referentiel/projets_production";
/**
* @param string $url
* @param Closure $itemsFunc take a php stdClass and should return an array
* @param Closure $mapFunc
*
* @return array
*/
function fetchFrom( $url, $itemsFunc, $mapFunc ) {
$json = file_get_contents( $url );
$obj = json_decode( $json );
$arr = $itemsFunc( $obj );
return array_map( $mapFunc,
$arr );
}
$villesOptions = fetchFrom( $villeUrl,
function ( $obj ) {
return $obj->data->data;
},
function ( $item ) {
return new ParentOption( $item->code, $item->libelle );
} );
$sitesOptions = fetchFrom( $siteUrl,
function ( $obj ) {
return $obj->data->data;
},
function ( $item ) {
return new ChildOption( $item->codeVille, $item->code, $item->libelle );
} );
$projetsOptions = fetchFrom( $projetUrl,
function ( $obj ) {
return $obj->data->data;
},
function ( $item ) {
return new ChildOption( $item->codeSite, $item->code, $item->libelle );
} );
// Exploitation du code
$selectBuilder = SelectBuilder::thisParent( 'ville_production', $villesOptions )
->withChild( 'site_production', $sitesOptions )
->withChild( 'projet_production', $projetsOptions )
->end();
echo $selectBuilder->script();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.