Titanium JIRA Archive
Alloy (ALOY)

[ALOY-368] Widgets should reference controllers within their standalone structure when using createController

GitHub Issuen/a
Resolution Date2013-03-11T15:52:58.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.1.0, 2013 Sprint 04
ReporterBert Grantges


Since Widgets are supposed to act as standalone instances, how do I go about creating multiple view/controllers and referencing them appropriately through createController? Example: WIdgetA has two views widget.xml menu.xml WidgetA controller wants to create an instance of menu.xml using createController var m = Alloy.createController("menu", {some object}).getView() Expectation is the above should reference the widgets menu view/controller Actual result – alloy tries to find the controller within the base alloy/controllers folder


  1. Fokke Zandbergen 2012-11-11

    Agree 100%, or at least support using WPATH in a widget controller to explicitly reference to other controllers within the widget:
       var row = Alloy.createController(WPATH('row'), arg).getView();
    I do see a WPATH implementation in the Alloy-generated widget.js:
       function WPATH(s) {
           var index = s.lastIndexOf("/"), path = index === -1 ? "MyWidget/" + s : s.substring(0, index) + "/MyWidget/" + s.substring(index + 1);
           return path;
    But using it results in:
    A workaround is to use:
       var row = Alloy.createWidget('MyWidget', 'row', arg).getView();
    Or is this actually the (undocumented) way to do it? You might think so since createWidget supports a controller name as a second parameter.
  2. Tony Lukasavage 2013-03-11

    The was handled in ALOY-530. The Alloy creation functions, like createController(), should be accessed in widget's like this:
       widget.createController('viewName', args);
    This will use the controllers contained within the widget. The same goes for the model and collection creation functions. createWidget() still references the global collection of widgets as it should.

JSON Source