PHPackages                             3xw/cakephp-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. 3xw/cakephp-utils

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

3xw/cakephp-utils
=================

CakePHP utils plugins

5.2.0(3mo ago)11.4k[1 issues](https://github.com/3xw/cakephp-utils/issues)4PHPPHP &gt;=8.2CI failing

Since Feb 19Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/3xw/cakephp-utils)[ Packagist](https://packagist.org/packages/3xw/cakephp-utils)[ RSS](/packages/3xw-cakephp-utils/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (3)Versions (91)Used By (4)

cakephp-utils plugin for CakePHP
================================

[](#cakephp-utils-plugin-for-cakephp)

This plugin is full of handly stuff

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require 3xw/cakephp-utils

```

In src/Application.php

```
use Cake\Http\BaseApplication;
...

class Application extends BaseApplication {

	...

  public function bootstrap()
  {
    parent::bootstrap();
    this->addPlugin('Trois/Utils', ['routes' => true]);
  }
	..
}

```

ORM
---

[](#orm)

### Behaviors

[](#behaviors)

- Sluggable Behavior
- Translate Behavior

### Rules

[](#rules)

- IsUniqueTranslationRule

### Associations

[](#associations)

#### MinMaxAssocationTrait

[](#minmaxassocationtrait)

```
namespace App\Model\Table
use Trois\Utils\ORM\Traits\MinMaxAssocationTrait;

class SubscriptionsTable extends Table
{
	use MinMaxAssocationTrait;

	public function initialize(array $config)
	{
		...

		// custom Association
    	$this->belongsToMinMax('MinPeriodes', [
      'type' => 'MIN',
      'field' => 'date',
      'className' => 'Periodes',
      'foreignKey' => 'subscription_id',
      'targetForeignKey' => 'periode_id',
      'joinTable' => 'subscriptions_periodes',
      'joinType' => 'LEFT'
			'joinAlias' => 'SP', // extra stuff: define yourself join alias
      'joinExtraConditions' => ['SP.was_present' => true] // extra stuff: add conditions on join clause
    ]);
	}
}

// OR
namespace App\Model\Table
use Trois\Utils\ORM\Traits\MinMaxAssocationTrait;

class LessonsTable extends Table
{
	use MinMaxAssocationTrait;

	public function initialize(array $config)
	{
		...

		// custom Association
    	$this->hasOneMinMax('MinPeriode', [
      'type' => 'MIN',
      'field' => 'date',
      'className' => 'Periodes',
      'foreignKey' => 'lesson_id',
      'joinType' => 'LEFT'
    ]);
	}
}

```

Shell
-----

[](#shell)

- MissingTranslations
- Token

### MissingTranslations

[](#missingtranslations)

```
tu_miss_i18n $model, ...$locales
```

### Token

[](#token)

```
ut_token username
```

View
----

[](#view)

- LngSwitchCell

Security
--------

[](#security)

### GUARD Component

[](#guard-component)

This component allows you to check constructed request object and clean it if needed...

in your src/Controller/AppController.php add following:

```
public function initialize()
{
    parent::initialize();

    ...

    // Auth
    $this->loadComponent('Auth', [...]);

    // Guard
    $this->loadComponent('Trois/Utils.Guard',[
      'autoload_configs' => [
        'Guard.requestBody' => 'guard_request_body'
      ]
    ]);

    ...
}

```

in config/guard\_request\_body.php

```
