Doctrine sortable entities for Nette framework.

v0.3.0 2018-02-21 14:24 UTC

This package is auto-updated.

Last update: 2024-04-27 20:49:48 UTC


Sooner or later you will have to implement sorting of your entities. For example categories, products on main page and so on. And why you should do this by yourself when everything you have to do is to copy & paste?


The best way to install librette/doctrine-sortable is using Composer:

$ composer require librette/doctrine-sortable

and enable librette extension in your `config.neon

	# add this line at the end of your extensions list
	librette.doctrine.sortable: Librette\Doctrine\Sortable\DI\SortableExtension

Simplest entity

namespace App;

use Kdyby\Doctrine\Entities\BaseEntity;
use Librette\Doctrine\Sortable\ISortable;
use Librette\Doctrine\Sortable\TSortable;

 * @ORM\Entity
class Category extends BaseEntity implements ISortable
	use TSortable;
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @ORM\GeneratedValue
	protected $id;

Trait TSortable

There is trait `TSortable` that implements basic sorting methods to your entity.
Everything you need is to call those methods in your service / presenter.

// you can move your entity up or down
// or you can put it before / after another one
// also you can set position directly

**Don't forget to persist and flush after you finish with sorting!**