How to call a Class from another folder inside com

2019-08-10 09:15发布

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?

2条回答
祖国的老花朵
2楼-- · 2019-08-10 09:51

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();
查看更多
冷血范
3楼-- · 2019-08-10 09:57

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

查看更多
登录 后发表回答