PHP code example of ddd / slug
1. Go to this page and download the library: Download ddd/slug 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/ */
ddd / slug example snippets
php
use Ddd\Slug\Model\SluggableInterface;
use Ddd\Slug\Service\SlugGeneratorInterface;
class Article implements SluggableInterface
{
private $createdAt;
private $title;
private $slug;
public function slugify(SlugGeneratorInterface $slugifier)
{
$this->slug = $slugifier->slugify(array($this->createdAt->format('Y'), $this->title));
}
// other methods...
}
php
use Ddd\Slug\Infra\SlugGenerator\DefaultSlugGenerator;
use Ddd\Slug\Infra\Transliterator\LatinTransliterator;
$article = new Article();
$article->setTitle('Hello world!');
$article->slugify(new DefaultSlugGenerator(array(new LatinTransliterator())));
echo $article->getSlug(); // writes "2013-hello-world"