Ive followed the instructions here:
for using Yii2 with my legacy web site.
Yii2 features like Active Record work beautifully.
But I can’t figure out how to use Assets within my application.
In a normal Yii2 web application you simply write:
and you’ll be able to use the functionality in whichever css or js files are defined in AppAsset.
But the register method requires a Yii2 view as its parameter - and I’m operating outside the MVC Yii2 environment - there’s no controller or view.
there’s no “$this” to register to.
I guess what I’m looking for is this:
The assets are already published into the root of the legacy application (because the legacy application sits on a server with another Yii2 application, and I’ve symlinked the Yii2 application’s assets directory).
So all I need is some reliable way to figure out the appropriate files to load, and output the appropriate link and script tags in my head tag.
Is there a way to get all the appropriate urls for a given Asset bundle without registering it?
Maybe the only solution is to just explicitly write the html to load the scripts and stylesheets from the existing symlinked Yii2 asset directories like so:
if I do that is there any chance the automatically generated directory names will change - will they change each time assets get re-published in the other Yii2 application?
e.g. will /assets/1a59b07c always be named /assets/1a59b07c - after future publishes have happened, can I count on that?
The legacy app is getting completely rewritten in the next year, so I’m ok if the code is a little kludgy. I just need to install features now, and would like to do it using Yii2, so I can easily port the code to the rewritten Yii2 app at a later date. All that’s missing is the appropriate assets.