开发者

External Php class in Yii?

Hello I need to use evalmath.class.php within a Yii applicat开发者_运维百科ion. How can I include it from my controller?

Something like this:

public function actionFormulas() {
    include('models/evalmath.class.php');
    $m = new EvalMath;
    ...
}

But the above code does not work. How can I include an external class within a controller?


In your example, to use include/require you probably need to add some path info with dirname(__FILE__).'/../models/...' or similar, but to do it within the Yii framework, you would first create an alias (usually in your main config file) with setPathOfAlias :

Yii::setPathOfAlias('evalmath', $evalmath_path);

Then you can use Yii::import like so:

Yii::import('evalmath', true);

and proceed as you were:

$m = new EvalMath();
..etc...


class ServiceController extends Controller
{
    public function actionIndex()
    {
        Yii::import('application.controllers.back.ConsolidateController'); // ConsolidateController is another controller in back controller folder
        echo ConsolidateController::test(); // test is action in ConsolidateController
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜