php – 如何从Yii中的模型访问控制器功能?

我想从模型内部访问Yii的createUrl()函数.

这是我在afterSave()中的代码.

 public function afterSave(){
    ...more code...

      $message = "Hi ".$this->firstname.' '.$this->lastname.',\n
            Welcome to XYZ. This is the mail that is sent for the activation of your account.\n
            Kindly click this link or copy paste it to the URL and register your account.'.$this->createUrl('/user/activate',array('id'=>$this->id,'key'=>$randomKey));
    ...morecode...
    }

这是必须纠正的路线.

$this->createUrl(‘/user/activate’,array(‘id’=>$this->id,’key’=>$randomKey))

显然,它给了我一个错误.那么如何在模型中使用createUrl()函数呢?

问候,

解决方法:

您可以使用Yii :: app()代替:

Yii::app()->createUrl('/user/activate',array('id'=>$this->id,'key'=>$randomKey))

相关问题:
 createUrl Yii – should we call it on controller view, or doesn’t matter?

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...