librette/doctrine-sortable
最新稳定版本:v0.3.0
Composer 安装命令:
composer require librette/doctrine-sortable
包简介
Doctrine sortable entities for Nette framework.
README 文档
README
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?
Installation
The best way to install librette/doctrine-sortable is using Composer:
$ composer require librette/doctrine-sortable
and enable librette extension in your `config.neon
extensions: # add this line at the end of your extensions list librette.doctrine.sortable: Librette\Doctrine\Sortable\DI\SortableExtension ``` Simplest entity --------------- ```php 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. ```php // you can move your entity up or down $entity->moveUp(); $entity->moveDown(); // or you can put it before / after another one $entity->moveBefore($anotherEntity); $entity->moveAfter($anotherEntity); // also you can set position directly $entity->setPosition(21); ``` **Don't forget to persist and flush after you finish with sorting!** ```php $this->em->persist($entity); $this->em->flush(); ```
统计信息
- 总下载量: 3.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-02-27