PHPackages                             d3yii2/d3codes - 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. d3yii2/d3codes

ActiveLibrary

d3yii2/d3codes
==============

Codes

4305↓50%1PHP

Since Mar 3Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/d3yii2/d3codes)[ Packagist](https://packagist.org/packages/d3yii2/d3codes)[ RSS](/packages/d3yii2-d3codes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Yii2](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)](https://www.yiiframework.com/)

Features
--------

[](#features)

Created as Yii2 moule. Actualy generate barccodes, bot can easy implement Qrcodes Functionality

- define code series by prefix and interval from and to
- creating codes from series and assigne to active record
- read codes and assign to active record
- label layouts
- label printing form windows server

DB Schema
---------

[](#db-schema)

[![DB Schema](/doc/DbSchema.png)](/doc/DbSchema.png)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require d3yii2/d3codes "*"

```

or add

```
"d3yii2/d3codes": "*"

```

to the `require` section of your `composer.json` file.

Configuration
-------------

[](#configuration)

### recorder and Readers

[](#recorder-and-readers)

Recorder generate new barcodes from defined series. For diferrent types define different components.

```
 'components' => [
        'palletCodeRecorder' => [
            'class' => 'd3yii2\d3codes\components\CodeRecorder',
            'codeName' => 'pallets bar code',
            'series' => [
                'p01' => [
                    'prefix' => 'p01',
                    'length' => 5,
                    'from' => 1,
                    'to' => 20000
                ]
            ],
            'modelClass' => 'wood\clasifiers\models\Pallet',
            'componentsSysModel' => 'sysModel'
        ],
        'codeReader' => [
            'class' => 'd3yii2\d3codes\components\CodeReader',
            'modelClassList' => [
                'wood\clasifiers\models\Pallet'
            ],
            'componentsSysModel' => 'sysModel'
        ],
    ]

```

### Printer

[](#printer)

For printing direct from the Windows server. Use Chrome for converting to PDF and for sending to printer use PDFtoPrinter

To composer add repository

```
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/uldisn/php-exec.git"
        },
```

```
# Bar code printer
BOUNCER_PRINTER=BouncerPrinter
PDFtoPrinter=H:\yii2\cewood\PDFtoPrinter.exe

# chrome
CHROME_PATH=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

```

Usage
-----

[](#usage)

### creating new barcode for model

[](#creating-new-barcode-for-model)

```
    $paletBarCode = \Yii::$app->palletCodeRecorder->createNewRecord($palletModelId);
```

### Find model by barcode

[](#find-model-by-barcode)

```
    $palletModel = \Yii::$app->palletCodeRecorder->codeReader($barcodeReadedByBarCodeScaner);
```

### Assign to model created code to other model record

[](#assign-to-model-created-code-to-other-model-record)

```
    Yii::$app->packCodeRecorder->assignCodeToOtherRecord($outPackId, $packCode);
```

### Adding code as attribute to model

[](#adding-code-as-attribute-to-model)

- find code, if code attached
- create new code and attach it, if no code attached

```
class BtlinePp extends BaseBtlinePp
{

    public function rules()
    {
        return array_merge(parent::rules(),[
            ['code','safe']
        ]);
    }

    public function attributeLabels()
    {
        return array_merge(parent::attributeLabels(),[
            'code' => 'Code'
        ]);
    }

    /**
     * @return string
     * @throws D3ActiveRecordException
     */
    public function getCode(): string
    {
        return Yii::$app->ppCodeRecorder->getCodeOrCreate($this->id);
    }
}
```

### Print barcode by printer

[](#print-barcode-by-printer)

```
use d3yii2\d3codes\actions\PrintCode;
class BatchController
{

    public function actions() {
        $OC = $this;
        return [
            'pp-print-barcode' => [
                'class' => PrintCode::class,
                'componentRecorderName' => 'ppCodeRecorder',
                'layout' => '@layout_barcode',
                'view' => 'print_barcode',
                'data' => static function(int $id) use ($OC){
                    return [
                        'model' => $OC->findModel($id),
                    ];
                }
            ],
        ];
    }
}
```

### reading in Controller and Form

[](#reading-in-controller-and-form)

For form use model d3yii2\\d3codes\\models\\CodeReader.

Controller

```
use d3yii2\d3codes\models\CodeReader;

        $codeReaderModel = new CodeReader();
        $codeReaderModel->componentCodeReaderName = 'codeReader';
        $post = Yii::$app->request->post();
        if($post && $codeReaderModel->load(Yii::$app->request->post())){
                    /** @var CwpalletPallet $palletModel */
                    $palletModel = $codeReaderModel->model;
        }
        if ($codeReaderModel->hasErrors()) {
            FlashHelper::modelErrorSummary($codeReaderModel);
        }
        return $this->render('manufacturing', [
            'packList' =>  $searchModel
                ->manufacturedPacks(true)
                ->all(),
            'packId' => $packId,
            'codeReaderModel' => $codeReaderModel
        ]);
```

form

```
                $form = ActiveForm::begin([
                    'id' => 'BauncerCodeReading',
                    'enableClientValidation' => false,
                    'errorSummaryCssClass' => 'error-summary alert alert-error',
                    'fieldConfig' => [
                        'template' => "{label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}",
                    ],

                ]);
                echo $form
                    ->field(
                        $codeReaderModel,
                        'code',
                        [
                            'inputOptions' => [
                                'autofocus' => 'autofocus',
                                'class' => 'form-control',
                                'tabindex' => '1'
                            ]
                        ])
                    ->textInput()
                    ->label('');

                echo ThButton::widget([
                    'label' => 'Process',
                    'id' => 'saveCode',
                    'icon' => ThButton::ICON_CHECK,
                    'type' => ThButton::TYPE_SUCCESS,
                    'submit' => true,
                    'htmlOptions' => [
                        'name' => 'action',
                        'value' => 'save',
                    ],
                ]);
                ActiveForm::end();
```

### Print from server

[](#print-from-server)

```
        try {

            $url = Yii::$app->urlManager->createAbsoluteUrl([
                '/cwstore/pack/print-barcode',
                'id' => $id
            ]);
            if(Yii::$app->bouncerPrinter->print($url)){
                FlashHelper::addSuccess('Etiķete nosūtīta uz izsitēja printera');
            }else{
                FlashHelper::addDanger('Radās kļūda drukājot etiķeti');
            }
        } catch (Exception $e) {
            FlashHelper::processException($e);
        }
```

### SQL Join

[](#sql-join)

SQL for getting code from model record

```
$sql = 'SELECT
  cwat_pack.cwat_pack,
  d3codes_code_record.full_code
FROM
  cwat_pack
  LEFT OUTER JOIN `d3codes_code_record`
    ON d3codes_code_record.model_id = :modelId
      AND cwat_pack.id = d3codes_code_record.model_record_id
      AND d3codes_code_record.`code_id` = :packCodeId
';
$params = [
   ':modelId' => SysModelsDictionary::getIdByClassName(CwatPack::class),
   ':packCodeId' => D3CodesCodeDictionary::getIdByName(Yii::$app->packAtlCodeRecorder->codeName),
];
```

Yii2 Query for getting code column

```
return $this
    ->queryForIndex()
    ->addSelect([
        'packCode' => 'd3codes_code_record.full_code',
    ])
    ->leftJoin(
        'd3codes_code_record',
        'd3codes_code_record.model_id = :modelId
            AND cw_store_pack.id = d3codes_code_record.`model_record_id`
            AND d3codes_code_record.`code_id` = :packCodeId',
        [
            ':modelId' => SysModelsDictionary::getIdByClassName(CwStorePack::class),
            ':packCodeId' => D3CodesCodeDictionary::getIdByName(Yii::$app->packCodeRecorder->codeName),
        ]
    )
    ->andFilterWhere(['LIKE', 'd3codes_code_record.full_code', $this->packCode])
    ;
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance56

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/542187ba859514d10d0952dca77df8ea889a9651b249d0b5b513da791fd2919b?d=identicon)[uldisn](/maintainers/uldisn)

---

Top Contributors

[![uldisn](https://avatars.githubusercontent.com/u/3525344?v=4)](https://github.com/uldisn "uldisn (56 commits)")

### Embed Badge

![Health badge](/badges/d3yii2-d3codes/health.svg)

```
[![Health](https://phpackages.com/badges/d3yii2-d3codes/health.svg)](https://phpackages.com/packages/d3yii2-d3codes)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
