如何在控制器中调用同一类函数


How to call the same class function in controller

我的示例代码。。我不知道怎么打

 class sample
    {
      public function actionExample()
      {
          code here
           // To call php function
      }
      public function a()
     {
        echo "test":
      }
   }
class className {
    function mone() {
       // CODE
    } 
    function mTwo() {
       // calling mone in mtwo
       $this->mone();
    }
}

bu使用$this例如:-

$this->functionName();

$this充当包含控制器的对象,使用它还可以访问变量和函数。例如:-

public $myvar;

您可以使用访问它

$this->myvar='value';

类似于功能

public function firstfun()
{
//some code
}

您可以使用称之为

$this->firstfun()

TRy

class sample
 {
      public function actionExample()
      {
          $this->a(); 
           // To call php function
      }
      public function a()
      {
         echo "test":
      }
  }

查看此项以获取更多参考http://www.yiiframework.com/forum/index.php/topic/6471-call-another-controllers-action/