1. Go to this page and download the library: Download pollen-solutions/field 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/ */
pollen-solutions / field example snippets
use Pollen\Field\FieldManager;
$field = new FieldManager();
$field->register('hello', function () {
return '<label>Hello : </label><input name="username" placeholder="Please, enter your name">';
});
echo $field->get('hello');
use Pollen\Field\FieldManager;
$field = new FieldManager();
$field->register('hello');
echo $field->get('hello', [
'attrs' => [
'name' => 'username',
'placeholder' => 'Please, enter your name'
],
'label' => 'Hello :'
]);
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;
class HelloField extends FieldDriver
{
public function render() : string{
return '<label>Hello : </label><input name="username" placeholder="Please, enter your name">';
}
}
$field = new FieldManager();
$field->register('hello', HelloField::class);
echo $field->get('hello');
use Pollen\Container\Container;
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;
$container = new Container();
$field = new FieldManager();
$field->setContainer($container);
class HelloField extends FieldDriver
{
public function render() : string{
return '<label>Hello : </label><input name="username" placeholder="Please, enter your name">';
}
}
$container->add('helloFieldService', HelloField::class);
$field->register('hello', 'helloFieldService');
echo $field->get('hello');
use Pollen\Field\FieldDriverInterface;
use Pollen\Field\FieldManager;
$field = new FieldManager();
$field->register('hello', function (FieldDriverInterface $driver) {
return '<label>Hello : </label><input name="username" placeholder="' . $driver->get('placeholder') . '">';
});
echo $field->get('hello', ['placeholder' => 'Please, enter your username']);
use Pollen\Field\FieldDriverInterface;
use Pollen\Field\FieldManager;
$field = new FieldManager();
$field->register('hello', function (FieldDriverInterface $driver) {
return '<label>Hello : </label><input name="username" placeholder="' . $driver->get('placeholder') . '">';
});
echo $field->get('hello', 'HelloUsername', ['placeholder' => 'Please, enter your username']);
echo $field->get('hello', 'HelloLogin', ['placeholder' => 'Please, enter your login']);
echo $field->get('hello', 'HelloUsername');
use Pollen\Field\FieldDriverInterface;
use Pollen\Field\FieldManager;
$field = new FieldManager();
$input = $field->get('input', [
/**
* Common driver parameters.
* --------------------------------------------------------------------------
*/
/**
* Main container HTML tag attributes.
* @var array $attrs
*/
'attrs' => [
'class' => '%s MyAppendedClass'
],
/**
* Content displayed after the main container.
* @var string|callable $after
*/
'after' => 'content show after',
/**
* Content displayed before the main container.
* @var string|callable $before
*/
'before' => function (FieldDriverInterface $driver) {
return 'content show before'
},
/**
* Name of the field in HTTP request of form submission.
* @var string|null $name
*/
'name' => null,
/**
* Current value.
* @var string|null $value
*/
'value' => null,
/**
* Field label.
* @var string|array|LabelDriver|false|null $label
*/
'label' => null,
/**
* Field label position.
* @var string $label_position
*/
'label_position' => 'before',
/**
* List of parameters of the template view|View instance.
* @var array|ViewInterface $view
*/
'view' => []
/**
* Input field driver parameters
* --------------------------------------------------------------------------
*/
/**
* HTML tag type attribute.
* @var string|null $type
*/
'type' => 'text',
]);
echo $input;
use Pollen\Field\FieldManager;
$field = new FieldManager();
$field->register('hello', function () {
return '<label>Hello : </label><input name="username" placeholder="Please, enter your name">';
});
if ($hello = $field->get('hello')) {
// Gets alias identifier.
printf('alias: %s <br/>', $hello->getAlias());
// Gets the base prefix of HTML class.
printf('base HTML class: %s <br/>', $hello->getBaseClass());
// Gets the unique identifier.
printf('identifier: %s <br/>', $hello->getId());
// Gets the index in related field manager.
printf('index: %s <br/>', $hello->getIndex());
}
// /var/www/html/views/field/hello.plates.php file
/**
* @var Pollen\Field\FieldTemplateInterface $this
*/
echo '<label>Hello : </label><input name="username" placeholder="Please, enter your name">';
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;
$field = new FieldManager();
$field->register('hello', new class extends FieldDriver{});
echo $field->get('hello', ['view' => [
/**
* View directory absolute path ( index is used by default if its null.
* @var string|null
*/
'template_name' => 'hello'
]]);
use Pollen\View\ViewManager;
use Pollen\Partial\FieldDriver;
use Pollen\Partial\FieldManager;
$field = new FieldManager();
$field->register('hello', new class extends FieldDriver{});
$viewEngine = (new ViewManager())->createView('twig')->setDirectory('/var/www/html/views/field/hello/');
echo $field->get('hello', ['view' => $viewEngine]);
use Pollen\Http\Response;
use Pollen\Http\ResponseInterface;
use Pollen\Field\FieldDriver;
use Pollen\Field\FieldManager;
$field = new FieldManager();
$field->register('hello', new class extends FieldDriver {
public function responseController(...$args) : ResponseInterface {
return new Response('Hello World');
}
});
// Gets the route url for the get HTTP method
echo $field->getRouteUrl('hello', null, [], 'get');
/** @var \Pollen\Field\FieldManagerInterface $field */
$button = $field->get('button', [
/**
* Text content of HTML button tag.
* @var string $content
*/
'content' => 'Send',
/**
* Type attribute in HTML tag.
* @var string $type
*/
'type' => 'button'
]);
echo $button;
/** @var \Pollen\Field\FieldManagerInterface $field */
$hidden = $field->get('hidden', [
/**
* Name of the field in HTTP request of form submission.
* @var string|null $name
*/
'name' => 'name',
/**
* Value of the field in HTTP request of form submission.
* @var string|null $value
*/
'value' => 'John Doe',
]);
echo $hidden;
/** @var \Pollen\Field\FieldManagerInterface $field */
$input = $field->get('input', [
/**
* Type attribute in HTML tag.
* @var string $type
*/
'type' => 'text'
]);
echo $input;