{"id":181,"date":"2014-09-27T10:07:19","date_gmt":"2014-09-27T15:07:19","guid":{"rendered":"http:\/\/devroar.com\/?p=181"},"modified":"2014-09-30T15:47:08","modified_gmt":"2014-09-30T20:47:08","slug":"extjs-5-0-app-getcontroller-fixes","status":"publish","type":"post","link":"http:\/\/devroar.com\/index.php\/2014\/09\/27\/extjs-5-0-app-getcontroller-fixes\/","title":{"rendered":"ExtJS 5.0 &#8211; app.getController() fixes"},"content":{"rendered":"<p><a href=\"http:\/\/www.sencha.com\"><img src=\"http:\/\/devroar.com\/wp-content\/uploads\/2014\/09\/extjs_logo.png\" alt=\"Sencha\" class=\"alignleft\" \/><\/a><br \/>\nRight out of the box I&#8217;ve noticed that the getController() method on the Ext.app.Application object instances does not function correctly when accessing it from the global app property configuration. I am not sure if this is a bug Sencha has overlooked in the open source version of ExtJS 5 or not, but with a few simple changes you can suppress the errors and continue on your merry way.<\/p>\n<p><!--more--><\/p>\n<h2 style=\"clear: left;\">Background Information<\/h2>\n<p>Before I begin I want to give a little background info about how these errors seem to come to light in my development. ExtJS has a application property called &#8220;appProperty&#8221;. When you set this property it enables you to access the app object globally from anywhere in your code like&#8230;<\/p>\n<p><code>appName.app<\/code><\/p>\n<p>The application object has a method called &#8220;getController&#8221; that you can use to get a reference to any controller in your application. It&#8217;s kind of the lazy man&#8217;s way of grabbing a reference in a complex app when you don&#8217;t want to or don&#8217;t have the time available to properly trace scope. It greatly helps for debugging scope issues and eliminating that as a factor. See <a href=\"http:\/\/docs.sencha.com\/extjs\/5.0\/apidocs\/#!\/api\/Ext.app.Application\" title=\"Ext.app.Application\">ExtJS documentation<\/a> for more information about the application object.<\/p>\n<p>The problem is, right out of the box this functionality is broken for me. Luckily with just a few changes you can get it back in working order. To do this you will need to modify the code in \/ext folder within your application (one level up from the \/app folder). But in order to have it load this code you have to double check one thing in the &#8220;app.json&#8221; file first.<\/p>\n<p>Inside your app.json file you need to look for the &#8220;js&#8221; block. If it looks like the below example then you need to modify it.<br \/>\n<code>\"js\": [<br \/>\n    {<br \/>\n        \"path\": \"${ext.dir}\/build\/ext-all-rtl-debug.js\"<br \/>\n    },<br \/>\n    {<br \/>\n        \"path\": \"app.js\",<br \/>\n        \"bundle\": true<br \/>\n    }<br \/>\n],<br \/>\n<\/code><\/p>\n<p>Change your block to match below:<br \/>\n<code>\"js\": [<br \/>\n    {<br \/>\n        \"path\": \"app.js\",<br \/>\n        \"bundle\": true<br \/>\n    }<br \/>\n],<\/code><\/p>\n<p>Now go find the following file in your \/ext folder.<br \/>\n<code>\/ext\/src\/app\/Application.js<\/code><\/p>\n<p>You want to search for the method &#8220;getController&#8221;, this is where our changes are.<\/p>\n<p>The first errors that I come across when trying to use getController() is<br \/>\n<code>TypeError: controller.doInit is not a function<\/code><\/p>\n<p>This will bring you to line 525 of Application.js<br \/>\n<code>if (me._initialized) {<\/code><\/p>\n<p>Change it to the following to suppress the error<br \/>\n<code>if (me._initialized && typeof controller.doInit != \"undefined\") {<\/code><\/p>\n<p>Now if you try to use getController() you&#8217;ll see a new error.<br \/>\n<code>TypeError: c.getModuleClassName is not a function<\/code><\/p>\n<p>To fix this one we need to look at line 507 of Application.js<br \/>\n<code>className = c.getModuleClassName();<\/code><\/p>\n<p>Modify this line to match<br \/>\n<code>className = c.moduleClassName;<\/code><\/p>\n<p>Now getController() should start behaving as it should! I&#8217;m not sure if this is just a bug in ExtJS they haven&#8217;t fixed or if I&#8217;m maybe using it wrong? but I somehow doubt that because i&#8217;m simply making a method call to the function with a valid controller path. Anyways. I hope this was of help to somebody else and possibly saved them some time and headaches.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Download article as PDF Right out of the box I&#8217;ve noticed that the getController() method on the Ext.app.Application object instances does not function correctly when accessing it from the global app property configuration. I am not sure if this is<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"http:\/\/devroar.com\/index.php\/2014\/09\/27\/extjs-5-0-app-getcontroller-fixes\/\">Read more &#8250;<\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[53],"tags":[94,95,101,103,102,105,56,57,58,104,98,99,96,97,100,54],"_links":{"self":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts\/181"}],"collection":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":9,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":201,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts\/181\/revisions\/201"}],"wp:attachment":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}