简体   繁体   中英

How to call a Class from another folder inside component folder?

I am using Yii 1.1.12 I have a class something like this:

project_folder/protected/components/myfolder/ClassA.php

class ClassA {

  public function getData() {
     return 'data';
  }

}

How to call getData() of ClassA from controller or from any other Class?

This should work Yii::import('application.components.myfolder.ClassA'); echo ClassA::getData();

Here example:

// /protected/components/A.php
class A extends CApplicationComponent
{

    public function getData()
    {
        return 'data';
    }
} 

//main config.
'components' => array(
        // ...
        'a' => array(
            'class' => 'application.components.A'
        ),

How to use:

echo Yii::app()->a->getData();
die();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM