承接 ip/sorter-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ip/sorter-bundle

Composer 安装命令:

composer require ip/sorter-bundle

包简介

Adds sorting functionality to your entities

README 文档

README

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require ip/sorter-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Add it to an entity

Add the Doctrine entity listener to your entitiy and don't forget to include all the use statements. Then extend your Entity with BaseSort as shown as in the example below.

<?php
// AppBundle/Entity/Test.php

// ...

use Doctrine\ORM\Mapping as ORM;
use Ip\SorterBundle\Model\BaseSort;

/**
 * @ORM\Entity
 * @ORM\Table(name="test")
 * @ORM\EntityListeners({"Ip\SorterBundle\EventListener\SortListener"})
 */
class Test extends BaseSort
{
    // ...
}

After this changes the sort value is already being set automatically for new database entries and is also correctly modified when you delete or update entries.

Step 3: Move items up and down

To move your items up or down in the sort order use the entity functions moveUp($controller) and moveDown($controller). You can, for example, call these functions in your controller. Your controller class has to extend the Symfony controller:

<?php
// AppBundle/Controller/testController.php

// ...

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

// ...

class testController extends Controller
{
    
    // ...
    
    public function moveUpAction($id)
    {
        // ...
        
        $testEntity->moveUp($this);

        // ...
    }
    
    public function moveDownAction($id)
    {
        // ...
        
        $testEntity->moveDown($this);

        // ...
    }

    // ...
}

(Optional) Step 4: Sorting within a supercategory

If your entity is a subcategory of another entity and should be sorted only within its own supercategory, you need to overwrite the function hasSuperCategory() in your entity.

In the example below we have a product sub category that needs to be sorted within the product category.

<?php
// AppBundle/Entity/ProductSubCategory.php

// ...

use Doctrine\ORM\Mapping as ORM;
use Ip\SorterBundle\Model\BaseSort;

/**
 * @ORM\Entity
 * @ORM\Table(name="product_sub_category")
 * @ORM\EntityListeners({"Ip\SorterBundle\EventListener\SortListener"})
 */
class ProductSubCategory extends BaseSort
{
    // ...
    
    /**
     * @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="productSubCategories")
     * @ORM\JoinColumn(name="product_category_id", referencedColumnName="id")
     */
    protected $productCategory;
    
    // ...
    
    /**
     * @return array
     */
    public function hasSuperCategory()
    {
        return array('productCategory' => $this->getProductCategory());
    }
}

An entity can have several supercategories. The array returned in hasSuperCategory just has to contain the values from them. The order of the supercategories has no influence on the sorting:

return array(
    'productCategory' => $this->getProductCategory(),
    'anotherSuperCategory' => $this->getAnotherSuperCategory()
);

统计信息

  • 总下载量: 146
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固