1. Go to this page and download the library: Download tatter/roster 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/ */
tatter / roster example snippets
$userName = service('roster')->user($userId);
namespace App\Rosters;
use App\Models\UserModel;
use Tatter\Roster\ModelRoster;
class UserRoster extends ModelRoster
{
protected $modelName = UserModel::class;
protected $field = 'username';
}
foreach ($comments as $comment):
namespace App\Rosters;
use App\Models\TagModel;
use Tatter\Roster\ModelRoster;
class TagRoster extends ModelRoster
{
protected $modelName = TagModel::class;
protected function getFieldValue(array $row): string
{
// Convert the database row from TagModel into its displayable form
$general = $row['general'];
$specific = $row['specific'];
return "[$general] $specific";
}
}
<h1><?= $post->title
namespace App\Rosters;
use App\Libraries\LinkApi;
use Tatter\Roster\BaseRoster;
class LinkRoster extends BaseRoster
{
/**
* Returns the handler-specific identifier used for caching
*/
protected function key(): string
{
return 'roster-links';
}
/**
* Loads all IDs and their names from the data source.
*/
protected function fetchAll(): array
{
$results = [];
$links = new LinkApi();
foreach ($links->list() as $link) {
$results[$link->uid] = $link->href;
}
return $results;
}
/**
* Loads a single ID and name from the data source.
*/
protected function fetch($id): ?string
{
$links = new LinkApi();
if ($link = $links->get($id)) {
return $link->href;
}
return null;
}
}