2

My intention is to create a working island of richness in a PHP based web application built with Yii 2.

That means I have a route, say /cars/index, that is currently being rendered server-side by Yii. Now I want to move the Yii template code to an Ember template.

The Ember code is assembled using Ember-CLI's ember build. I have created softlinks from inside the Yii public web directory to the two Ember files dist/vendor.js and dist/app.js so that the code can be accessed from a web browser. For this storeConfigInMeta: false had to be set as depicted here: ember-cli meta config/environment file.

While I have successfully got Ember to run my code by using the ember-islands addon the goal is to keep the MVC structure, making use of the Ember application's models and controllers. This is to allow for a potential full shift to client-side rendering in the future, and it cannot be achieved with components only.

Unfortunately all I found when researching this topic was that I had to disable the creation of an Ember.Application and then create such an object by hand. This approach does not fit my use-case because that way I cannot make use of Model and Controller code in the server-side templates. Or can I?

Plus, how can we then route to /cars/index without letting the framework throw an error about Yii's route not matching this format (currently something like /index.php?r=cars/index)? (Uncaught UnrecognizedURLError)

Community
  • 1
  • 1

1 Answers1

0

Try the ember-export-application-global add-on, it will allow you to access the application instance created with Ember CLI. This way you can access your Ember application directly from the server code.

Jon Koops
  • 8,801
  • 6
  • 29
  • 51
  • Thanks for this, I didn't know the global wouldn't be exported in production mode. Unfortunately this doesn't answer the question of how to move from IndexRoute to CarsRoute using code that is not present in the Ember application itself. –  Nov 27 '15 at 16:58
  • @Pyro You want to define a route or transition to an existing route? – Jon Koops Nov 27 '15 at 17:27
  • I want the application to start at the route that is suited for the page, but not infer that information by the URL (because it can't do that) but manually. If in order to accomplish that I have to transition from IndexRoute to CarsRoute, so be it. But the end result should be cars/index getting rendered and the models getting fetched via AJAX. –  Nov 27 '15 at 18:11
  • Wouldn't is just be possible to define a Cars route like so: `this.route('cars', { path: 'cars/index' })`? Ember relies heavily on URLs to to what it needs to. Maybe you can set the location adapter to get rid of that? http://emberjs.com/api/classes/Ember.Location.html#toc_autolocation – Jon Koops Nov 29 '15 at 23:35