我想从模型内部访问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?