Components of yii

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.