简体   繁体   English

如何从自定义HTML访问使用Ember-CLI构建的Ember应用程序的路由?

[英]How to access a route of an Ember application built with Ember-CLI from custom HTML?

My intention is to create a working island of richness in a PHP based web application built with Yii 2. 我的意图是在使用Yii 2构建的基于PHP的Web应用程序中创建丰富的工作岛。

That means I have a route, say /cars/index , that is currently being rendered server-side by Yii. 这意味着我有一条路由,例如/cars/index ,该路由当前由Yii呈现在服务器端。 Now I want to move the Yii template code to an Ember template. 现在,我想将Yii模板代码移至Ember模板。

The Ember code is assembled using Ember-CLI's ember build . 使用Ember-CLI的ember build汇编Ember代码。 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. 我已经从Yii公共web目录内部创建到两个Ember文件dist/vendor.jsdist/app.js软链接,以便可以从Web浏览器访问代码。 For this storeConfigInMeta: false had to be set as depicted here: ember-cli meta config/environment file . 对于此storeConfigInMeta: false必须按如下所示设置storeConfigInMeta: falseember-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. 尽管我已经通过使用ember-islands插件成功使Ember运行我的代码,但目标是保留MVC结构,并利用Ember应用程序的模型和控制器。 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. 不幸的是,在研究此主题时,我发现的所有内容是我必须禁用Ember.Application的创建,然后手动创建此类对象。 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. 这种方法不适合我的用例,因为那样我就无法在服务器端模板中使用Model和Controller代码。 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 )? 另外,我们如何才能路由到/cars/index而不让框架抛出与Yii路由不匹配此格式的错误(当前类似/index.php?r=cars/index )? ( Uncaught UnrecognizedURLError ) 未捕获的UnrecognizedURLError

Try the ember-export-application-global add-on, it will allow you to access the application instance created with Ember CLI. 尝试ember-export-application-global插件,它将允许您访问使用Ember CLI创建的应用程序实例。 This way you can access your Ember application directly from the server code. 这样,您可以直接从服务器代码访问Ember应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM