PHP code example of 10quality / php-class-to-javascript

1. Go to this page and download the library: Download 10quality/php-class-to-javascript 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/ */

    

10quality / php-class-to-javascript example snippets


use TenQuality\Traits\CastJavascriptTrait;

class MyClass
{
    use CastJavascriptTrait;
}

$class = new MyClass;
$class->toJS();
$class->to_js(); // Alias

class MyClass
{
    use CastJavascriptTrait;

    protected $hidden = [
        'propertyA',
        'property_2',
    ];
}

class MyClass
{
    use CastJavascriptTrait;

    // (1) As array
    protected $castingProperties = [
        'propertyA',
        'property_2',
    ];
}

class MyClass
{
    use CastJavascriptTrait;

    protected $attributes = [
        'id',
        'name',
    ];

    // (1) As property mapping
    protected $castingProperties = 'attributes';
}