Download the PHP package mustang/nestedsets without Composer

On this page you can find all versions of the php package mustang/nestedsets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package nestedsets

mustang/nestedsets

ThinkPHP5的nestendsets的扩展,参考了gmars的nestendsets,附加了rebuild方法。

安装方法

获取nestedsets实例

结合模型使用

一般使用nestedsets是结合模型使用的,但是此扩展中并没有使用tp5中模型的特性进行增删改查,那样的话让我们的扩展包会显得更为厚重。但是模型的特性在我们的使用中是有必要的。


在项目中需要配置的参数和你的数据表字段对应就行:

/**
 * @var string 左键
 */
private $leftKey = "lft";

/**
 * @var string 右键
 */
private $rightKey = "rht";

/**
 * @var string 父亲字段
 */
private $parentKey = "pid";

/**
 * @var string 节点深度
 */
private $levelKey = "lev";

/**
 * @var string 主键
 */
private $primaryKey = "id";

我的数据表结构为:


在模型中配置nestedsets并使用:

在模型中配置的方式为在模型中定义一个public $nestedConfig属性。注意,名称必须是nestedConfig

例如:

然后就可以实例化使用了

这样就实例化了一个Mptt对象,紧接着就可以调用其中的方法进行使用了。

实例化时传入配置参数:

其实上边直接配置已经很方便了。但是你不想在模型中配置该参数也可以在实例化时传入配置,例如:

这种方式也是允许的,但是如果模型中的配置和直接传参都使用时模型中配置的参数不会生效只生效实例化时传入的参数。

原生配置使用

这种方式是考虑如果你存在的表没有必要创建模型时的使用。

这时候就没有模型供我们使用,所以实例化时第一个参数为表名,例如:

需要注意的是,传入的表名必须是完整表名。这种方式如果要对字段配置只能在实例化时传入参数。

在项目中使用nestedsets

如果你要创建一个节点:

parentId是要创建节点的父亲节点。

data是数据表中其他的字段例如名称、描述信息等,必须是数组

insert方法的本来形式如下:

删除节点

删除节点会删除该节点下的所有后代节点,这个在逻辑上来说是合理的。

移动某一个节点成为另一个的子节点

移动一个节点成为另一个节点的子节点的操作在实际使用中使用比较广泛

移动某一个节点到另一个节点的前或者后

这种操作多见于改变节点的顺序上实用性也非常强

该方法的原型为:

重建全表左右值和深度

适用于程序错误或人为改动将表破坏的情况

可能有人会疑惑该扩展为何没有修改节点的方法。其实这不是nestedsets该做的事情。对于节点的修改在数据结构的层面来讲就是节点位置的移动。至于数据表中其他字段的修改,例如name,description等则使用框架给我们提供的字段修改的方法要更加方便。


All versions of nestedsets with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mustang/nestedsets contains the following files

Loading the files please wait ....