Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set the ApplicationController in Ember.Router

I there any other possibility to handle with Ember.Router controllers and views? My app structure generally depends on require.js which takes care of the corresponding dependencies.

In my example i'm doing the App.ApplicationController thing as the main router controller.

Here's a jsfiddle: http://jsfiddle.net/mediastuttgart/uMKGt/1/

But is there any chance to set this manually? I've found this commit message https://github.com/emberjs/ember.js/commit/be69395f5eec4187b1df052d7386bcda45f79475 where i can see, how to set the controller and view manually (anyway couldn't get this working). But couldn't find any example like:

App = Ember.Application.create();

App.MyController = Ember.Controller.extend({});
App.MyView = Ember.View.extend({});

Router = Ember.Router.extend({
    applicationController : App.MyController,
    root : Ember.Route.extend({
        index : Ember.Route.extend({
            route : '/',
            connectOutlets : function (router) {
                router.get('applicationController').connectOutlet(App.MyView);
            }
        })
    }),
    ...
});

EDIT

I'm trying to explain this a little bit more in detail. While we use require.js to manage or dependencies, we have multiple controllers which are responsible for their own parts of the entire application. Let's say we have a newsletter signup form. The controller used for this scenario is structured in

- app
-- controller
--- newsletter
---- signup.js
--- cart
--- checkout
-- view
-- model
-- router
-- template

As we use a custom function to generate namespaces Em.Provide('App.Controller.Newsletter'); which creates an object at App.Controller.Newsletter. This object now serves as controller base for our entire newsletter application. Beginning with App.Controller.Newsletter.Signup = Ember.Controller.extend({}); we need to pass in this instance as the "ApplicationController" for the router. As you can see, we can't just use App.ApplicationController to instantiate a controller for Ember.Router.

like image 379
Michael Alexander Freund Avatar asked Jun 25 '12 15:06

Michael Alexander Freund


1 Answers

Don't know anything about requirejs, but I think the only thing is to define an

App.ApplicationController = Ember.Controller.extend({...behavior here...})

and then, when calling

App.initialize()

The framework will then inject automatically this controller in the router.

like image 157
sly7_7 Avatar answered Nov 16 '22 23:11

sly7_7