简体   繁体   中英

Static function not calling in PHP 5.3 Yii Framework

I've created one controller CommonController (not generated by gii) in my Yii App. It contains lot of static methods.

Ex.

class CommonController extends Controller{

public static getDate(){
   ...
   ...
}

public static getInfo(){
   ...
   ...
}

etc...

}

On Localhost I am using PHP 5.4 and calling static method from another controller/model/view: Ex.

CommonController::getDate()

and its working fine.

Now I've moved app on server which has PHP 5.3 version. I've debugged a lot and found the issue that CommonController::getDate() this class is not getting called and its breaking my app.

I've used this stuff everywhere so how can I solve this issue.

Need help.

Thanks.

You should simply try to import the class before using it :

Yii::import('application.controllers.CommonController');

http://www.yiiframework.com/doc/api/1.1/YiiBase#import-detail

Yii doesn't use its autoloader for controllers. That's why you should import them before using inside other classes.

Anyway, controllers shouldn't be used to share functionalities over other classes in the project. You may create helper classes (under protected/helpers ) and add them into autoloader (add 'application.helpers.*' into import array of your config file).

I've tried all the above things and it didn't work for me. So finally I've changed my PHP Version 5.3 to 5.4.10 (which's the stable oldest version) and it worked for me.

Thanks for you help and support.

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