PHP code example of yiiviet / yii2-n2w

1. Go to this page and download the library: Download yiiviet/yii2-n2w 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/ */

    

yiiviet / yii2-n2w example snippets



/**
* @property int $amount
*/

class Order extends ActiveRecord {

    public function behaviors() {
        return [
            'n2w' => [
                'class' => 'yiiviet\n2w\Behavior',
                'property' => 'amount',
                'unit' => 'đồng'
            ]
        
        ];
    
    }

}

$order = Order::findOne(1);

print $order->amount; // 100000
print $order->amountFormat; // Một trăm ngàn đồng



/**
* @property int $amount
* @property int $tax
*/

class Order extends ActiveRecord {

    public function behaviors() {
        return [
            'n2w' => [
                'class' => 'yiiviet\n2w\Behavior',
                'properties' => ['amount', 'tax'],
                'unit' => 'đồng'
            ]
        
        ];
    
    }

}

$order = Order::findOne(1);

print $order->amount; // 100000
print $order->amountFormat; // Một trăm ngàn đồng

print $order->tax; // 10000
print $order->taxFormat; // Mười ngàn đồng



/**
* @property int $amount
* @property int $tax
*/

class Order extends ActiveRecord {

    public function behaviors() {
        return [
            'n2w' => [
                'class' => 'yiiviet\n2w\Behavior',
                'properties' => ['amount', 'tax'],
                'unit' => 'đồng',
                'suffix' => 'Convert'
            ]
        
        ];
    
    }

}

$order = Order::findOne(1);

print $order->amount; // 100000
print $order->amountConvert; // Một trăm ngàn đồng

print $order->tax; // 10000
print $order->taxConvert; // Mười ngàn đồng