PHP code example of librette / doctrine-sortable

1. Go to this page and download the library: Download librette/doctrine-sortable 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/ */

    

librette / doctrine-sortable example snippets


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;
}

// 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);

$this->em->persist($entity);
$this->em->flush();