Tips/help on integrating JS framework (OJET) into Yii views and standard controller (not REST)

Hi,

I’m in the process of migrating/rewriting an old application (Winforms .Net 4.8) and for various reasons will be mixing standard Winforms based application/controls, Yii2 applications (both REST and Web Controller based), VueJs and Oracle JET; at this stage OJET (JS toolkit to develop SPA, npm/cli for dependencies and build/dev with file watching, live/hot reload, etc.) is being used to provide “mini applications” inside the .Net based application (e.g.: data visualization, Gantt); this works well enough since I can develop the OJET application, run any npm and cli commands to manage dependencies, minification, hot reload, etc. and then when ready just build for release and place the resulting HTML+JS+CSS files in the server and load them inside a form using an embedded browser control (CefSharp).

At some point I’ll need to have these OJET applications “inside” a standard view, meaning I have a Yii2 based application and need to render a partial view that will contain the OJET application. My existing workflow won’t work and I’m looking into ways to automate it and allow development of OJET (or any other similar framework, like VueJS) and integration into the Yii2 based applications.

Things I haven’t solved:

  • OJET uses requirejs, that will then manage all the JS loading my app needs, so I’ll have to make sure Yii2 publishes all files/assets; should not be an issue, but I’m still unsure about it;
  • When developing, OJET watches changes to my files and “builds” the index.html, CSS and JS files, and deploys them to a build/staging folder; don’t think this will work with asset publishing,or even having a folder in my public/web folder
  • There are different files for development and for release, and I need a way to detect that I’m in dev mode or in production mode;
  • I need a way to “move” the OJET HTML into a PHP view/file that I can render inside my Yii2 views; this should be easy as I can just remove anything that is not my app’s markup from the compiled index.html file.

So, after all this :slight_smile: any suggestions, pitfalls, ideas? Has anyone done something similar to this already that can share some insights into how to improve workflow and, as much as possible, automate the file processing and “view building”?

Thanks.

You have two ways

  1. If the js resources are used in single view and are accessible from web folder, I always go with View::registerJsFile()
  2. If you have anything than simple case stated in (1), then go for asset bundles
    Application Structure: Assets | The Definitive Guide to Yii 2.0 | Yii PHP Framework
1 Like

Hi,

I’ll probably use the View::registerJsFile method, as I already have a View implementation to handle some other requirements in this app. Going with AssetBundle will require many classes that won’t be used for anything else besides these “mini” apps.

But that is the easier part :), creating some workflow that makes this “simple” and doesn’t require manually updating the final files has been more complicated, I’m looking into phing/ant/npm/etc. all solutions seem hacky.

Wish you success!