rass
rass

Reputation: 107

Yii2 Creating url to folder inside root

My problem is somewhat simple but despite trying different Yii2 functions I'm unable to get the correct URL to the audio player components I would like to install.

So, to keep things short. Yii2 is installed on localhost with localhost/yii2app/ being the index. This is based on yii2 advanced app and the structure is as follows:

-Yii2app
-- frontend
-- backend
-- ...
-- flashplayer

Now, When i'm in sample view I would like to display the player to play the deisred sample. The url path of location is:

http://localhost/yii2app/frontend/web/sample/1

I wish to implement the player in this view:

<object type="application/x-shockwave-flash" value="<?= Url::to('/flashplayer/', true); ?>player.swf" width="200" height="20" id="dewplayer" name="dewplayer">
    <param name="movie" value="<?= Url::home(false) . '/flashplayer/' ?>player.swf">
    <param name="flashvars" value="mp3=test.mp3" />
    <param name="wmode" value="transparent" />
</object>

As you can see I've trying different approaches, but no success so far. I'm getting following urls:

/yii2app/frontend/web/flashplayer/player.swf

or

http://localhost/flashplayer/player.swf

Obviously, both of them are incorrect. The URL I need is:

/yii2app/flashplayer/player.swf

Is it possible to get just the main path of application without controller's route in url? I don't want to include the webroot path, but server one. Also, this should work even when the application is moved to production server.

I will appreciate any ideas.

Upvotes: 1

Views: 904

Answers (1)

moein kh
moein kh

Reputation: 479

you can copy your index.php,assest,css,favicon.ico and robots.txt from yii2app/frontend/web/ and then pasted them in yii2app file and replace your index.php in the yii2app file with:

<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/frontend/config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/common/config/main.php'),
require(__DIR__ . '/common/config/main-local.php'),
require(__DIR__ . '/frontend/config/main.php'),
require(__DIR__ . '/frontend/config/main-local.php')
);

$application = new yii\web\Application($config);
$application->run();

and then when you open yii2app in the localhost you can see your frontend/web with this url:

localhost/yii2app

Upvotes: 1

Related Questions