phpyiiyii-componentsyii-modules

How to load Yii modules component?


When I did the steps like described here I just get with config in config/main.php:

<?php
return array(
  'modules' => array(
    'tracking' => array(
      'components' => array(
        'tracking' => array(
          'foo' => 'bar'
)))));

this result, when I var_dump Yii::app()->getModule('tracking'):

object(TrackingModule)#148 (20) {
  ["defaultController"]=>  string(7) "default"
  ["layout"]=>  NULL
  ["controllerNamespace"]=>  NULL
  ["controllerMap"]=>  array(0) {}
  ["_controllerPath":"CWebModule":private]=>  NULL
  ["_viewPath":"CWebModule":private]=>  NULL
  ["_layoutPath":"CWebModule":private]=>  NULL
  ["preload"]=>  array(0) {}
  ["behaviors"]=>  array(0) {}
  ["_id":"CModule":private]=>  string(8) "tracking"
  ["_parentModule":"CModule":private]=>  NULL
  ["_basePath":"CModule":private]=>  string(79) "..."
  ["_modulePath":"CModule":private]=>  NULL
  ["_params":"CModule":private]=>  NULL
  ["_modules":"CModule":private]=>  array(0) {}
  ["_moduleConfig":"CModule":private]=>  array(0) {}
  ["_components":"CModule":private]=>  array(0) {}
  ["_componentConfig":"CModule":private]=>  array(1) {
    ["tracking"]=> array(1) {
      ["foo"]=> string(4) "bar"
    }
  }
  ["_e":"CComponent":private]=>  NULL
  ["_m":"CComponent":private]=>  NULL
}

I expect that I can access modules component via Yii::app()->getModule('tracking')->tracking. But as you see Yii::app()->getModule('tracking') has no component, just its config.

Any suggestions what I am doing wrong?


Solution

  • You have to specify class for component, for example in config (TrackingClassName):

    'modules' => array(
        'tracking' => array(
            'foo' => 'bar',
            'components' => array(
                'tracking'  => array(
                   'class' => 'TrackingClassName', 
                ),...