Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call function in another controller in Yii

Tags:

oop

php

yii

I've created 2 controllers in my Yii application: FirstController.php and SecondController.php in default controller path.

FirstController.php:

<?php
 class FirstController extends Controller {
  public static function returnFunc() { return 'OK'; }
}

SecondController.php:

<?php
 class SecondController extends Controller {
  public function exampleFunc() {
     $var = First::returnFunc();
  }
}

When I try to execute exampleFunc() in SecondController, Yii throw the error:

YiiBase::include(FirstController.php) [<a href='function.YiiBase-include'>function.YiiBase-include</a>]: failed to open stream: No such file or directory

Calling FirstController::returnFunc() similarly don't work.

I'm newbee in OOP and Yii framework. What's the problem?

like image 367
ZhukovRA Avatar asked Oct 26 '10 09:10

ZhukovRA


1 Answers

I've solved this problem. The autoloader doesn't load controllers.

It was in config/main.php:

'import' => array(
    'application.models.*',
    'application.components.*',
),

All work with this:

'import' => array(
    'application.models.*',
    'application.components.*',
    'application.controllers.*',
),
like image 182
ZhukovRA Avatar answered Sep 21 '22 00:09

ZhukovRA