

Here’s what our Base.js controller looks like: Ext.define(' computer scientists or other coding professionals, an understanding of specific coding frameworks like Ext JS may be a useful skill. And even if we don’t use it right away, starting with a Base controller will save us refactoring time in the future when we do need it. If we create a base controller from which all other controllers inherit, we can add any common methods that are applicable to all our controllers. Why Base? As you develop your application, you’ll probably come across a lot of areas where you repeat the same code over and over within your controllers. When our app was generated, Sencha Cmd created a simple controller named Main in the controller folder. So if you have a controller that will deal with a “car”, the best-practice for naming the controller would be “Cars”. Naming Convention Alert: When naming controllers, the suggested convention is uppercase-plural. Therefore, it is generally suggested that you create a single controller for each main area of concern for your app. Beyond merely listening to events, controllers can also be made “aware” of particular stores, views, etc., and in turn provide very helpful auto-generated getters for the same. While this is certainly possible, it is not advised. Technically, you could create a “god” controller for your app, a single controller to handle every event within your app.

As with the load event of the store, your controller can also listen to the itemdblclick event of the grid and do whatever you need to do in response to the announcement of that event. When you double-click on a row, an itemdblclick event is fired. In your controller (and elsewhere), you can listen to this event and hand off whatever custom processing you’d like to methods that you define within the controller. So for example, when your store makes an AJAX request via a server proxy, the store (via the proxy) will fire a load event. Pretty much every component (views) and data object (stores, models) will fire off a number of events based on the context. By design, ExtJS 4 is event driven, so your controllers are really like souped up event listeners. A Bit About ControllersĬontrollers within ExtJS 4 MVC apps are the brains of your application, the place where the vast majority of your application’s functionality and logic will (and should be) stored. NOTE: Code for this installment can be found on GitHub. Instead of doing that, let’s just wait to make it until later and spend our time on something that will get us closer to being able to use it.

However, our app is not quite ready to support a data model of any kind, so we’d make it and have to set it aside until later. We could, of course, plow ahead with making a data model. In the last post, I said we were going to start making data models and whatnot.
