PHP code example of karakum / yii2-path-registry

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

    

karakum / yii2-path-registry example snippets




use yii\db\Migration;

ganizer extends Migration
{
    public function up()
    {
        $path = new m160606_163120_path_organizer_init();
        $path->up();
    }

    public function down()
    {
        $path = new m160606_163120_path_organizer_init();
        $path->down();
    }
}

<?=

$avatarPath = Yii::$app->pathManager->getPath('avatar');
$path = $avatarPath->getPath();                          			//  '7b08aea20ff07411b74b97ebe7fe6bf8'
$directory = $avatarPath->getFullPath();                            //  '/var/www/yii2-app/web/uploads/avatar/7b08aea20ff07411b74b97ebe7fe6bf8'
$filename = $avatarPath->getFullPath('photo.png');                  //  '/var/www/yii2-app/web/uploads/avatar/7b08aea20ff07411b74b97ebe7fe6bf8/photo.png'
$file = $avatarPath->getPath('photo.png');                 			//  '7b08aea20ff07411b74b97ebe7fe6bf8/photo.png'
$imgSrc = $avatarPath->getUrl($file, [                              //  'http://mysite.com/uploads/avatar/7b08aea20ff07411b74b97ebe7fe6bf8/photo.png'
    'id' => 1,
    'name' => 'Photo_name.png'
]);

$filesPath = Yii::$app->pathManager->getPath('files');
$path = $filesPath->getPath();                          			//  '06524c83dc331625baeece8a8b4b5022'
$directory = $filesPath->getFullPath();                             //  '/var/www/yii2-app/secure/06524c83dc331625baeece8a8b4b5022'
$filename = $filesPath->getFullPath('secret.txt');      			//  '/var/www/yii2-app/secure/06524c83dc331625baeece8a8b4b5022/secret.txt'
$file = $filesPath->getPath('secret.txt');              			//  '06524c83dc331625baeece8a8b4b5022/secret.txt'
$fileUrl = $filesPath->getUrl($file, [                              //  'http://mysite.com/download/2/Secret_data.txt'
    'id' => 2,
    'name' => 'Secret_data.txt'
]);