微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐