PHP code example of sergeymakinen / yii2-facades

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

    

sergeymakinen / yii2-facades example snippets


$random = Yii::$app->security->generateRandomString(128);

$random = Security::generateRandomString(128);

$users = Yii::$app->db->createCommand('SELECT * FROM users;')->queryAll();

$users = Db::createCommand('SELECT * FROM users;')->queryAll();

$price = Yii::$app->formatter->asCurrency(123456.78, 'USD');

$price = Formatter::asCurrency(123456.78, 'USD');

$value = YourFacadeName::getFoo()

YourFacadeName::setFoo($value)

public static function cache($key, $default, $duration = 0, $dependency = null)

$users = Cache::cache('users', function () {
    return app\models\Users::findAll();
}, 3600);

public static function get($key, $default = false)

$options = Cache::get('options', function () {
    return [
        'option1' => false,
        'option2' => true
    ];
});

public static function bare($statusCode = 204, array $headers = [])

public function actionCreate()
{
    // ...
    return Response::bare(201);
}

public static function html($data, array $headers = [])

public function actionIndex()
{
    // ...
    return Response::html($this->render('index'), [
        'Cache-Control' => 'no-cache'
    ]);
}

public static function json($data, array $headers = [])

public function actionList()
{
    // ...
    return Response::json(Db::createCommand('SELECT * FROM users')->all());
}

public static function jsonp($data, $callback = 'callback', array $headers = [])

public function actionApi($callback)
{
    // ...
    return Response::jsonp([
        'success' => true,
        'response' => $data
    ], $callback);
}

public static function raw($data, array $headers = [])

public function actionCreate()
{
    // ...
    return Response::raw($binary, [
        'Content-Type' => 'application/octet-stream'
    ]);
}

public static function xml($data, array $headers = [])

public function actionCreate()
{
    // ...
    return Response::xml([
        'success' => true,
        'response' => $data
    ]);
}

class YourFacadeName extends Facade
{
    /**
     * @inheritdoc
     */
    public static function getFacadeComponentId()
    {
        return 'yourFacadeComponentName'; // Yii::$app->yourFacadeComponentName
    }
}

YourFacadeName::hello('world');

Yii::$app->get('yourFacadeComponentName')->hello('world');