When we create a module, the corresponding path alias has been created.
For example, we have defined a module: www
12345 |
‘modules‘ => array ( ‘www‘ => array ( ‘class‘ => ‘applications.modules.www.WwwModule‘ , ), ), |
Print:
Echo yii: APP ()-> getpathofalias ('www ')
You will find that the WWW alias has been directed to our www module.
Assume that the following directory is available in our www module:
WWW
-Components
-- Apibase. php
-Extensions
-Vendors
-- Curl. php
How can I load the components or other third-party packages?
As follows:
123456789 |
‘modules‘ => array ( ‘www‘ => array ( ‘class‘ => ‘applications.modules.www.WwwModule‘ , ‘components‘ => array ( ‘api‘ => array ( ‘class‘ => ‘www.components.ApiBase‘ ), ‘curl‘ => array ( ‘class‘ => ‘www.vendors.Curl‘ ), ), ), ), |
So how can I get it in the controller:
As follows:
12 |
$api = $this ->getModule()->api; $curl = $this ->getModule()->curl; |
$ This is the current controller.
Note: yii: APP ()-> curl is not used to obtain component, because we define component into modules.
What if other modules want to use our extensions?
1 |
$curl = Yii::app()->getModule( ‘www‘ )->curl; |
Of course, for public extensions, it is not recommended to define a single module or put it in the external components. Then you can use yii: APP ()-> curl to get it.