配置私人郵件擴展時出現問題。 這裏是保護的的構造/配置/ main.phpYii私人郵件擴展「Method User :: getFullName not defined」
'message'=>array(
'userModel'=>'User',
'getNameMethod' => 'getFullName',
'getSuggestMethod' => 'getSuggest',
'receiverRelation'=> array(
CActiveRecord::BELONGS_TO, 'User', 'on'=>'User.id = receiver_id'
),
'senderRelation'=> array(
CActiveRecord::BELONGS_TO, 'User', 'on'=>'User.id = sender.id'
),
),
這是保護的代碼/模塊/消息/ MessageModule.php
<?php
class MessageModule extends CWebModule
{
public $defaultController = 'inbox';
public $userModel = 'User';
public $userModelRelation = null;
public $getNameMethod;
public $getSuggestMethod;
public $senderRelation;
public $receiverRelation;
public $dateFormat = 'Y-m-d H:i:s';
public $inboxUrl = array("/message/inbox");
public $viewPath = '/message/default';
public function init()
{
if (!class_exists($this->userModel)) {
throw new Exception(MessageModule::t("Class {userModel} not defined", array('{userModel}' => $this->userModel)));
}
foreach (array('getNameMethod', 'getSuggestMethod') as $methodName) {
if (!$this->$methodName) {
throw new Exception(MessageModule::t("Property MessageModule::{methodName} not defined", array('{methodName}' => $methodName)));
}
if (!method_exists($this->userModel, $this->$methodName)) {
throw new Exception(MessageModule::t("Method {userModel}::{methodName} not defined", array('{userModel}' => $this->userModel, '{methodName}' => $this->$methodName)));
}
}
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'message.models.*',
'message.components.*',
));
}
public function beforeControllerAction($controller, $action)
{
if (Yii::app()->user->isGuest) {
if (Yii::app()->user->loginUrl) {
$controller->redirect($controller->createUrl(reset(Yii::app()->user->loginUrl)));
} else {
$controller->redirect($controller->createUrl('/'));
}
} else if (parent::beforeControllerAction($controller, $action)) {
// this method is called before any module controller action is performed
// you may place customized code here
return true;
} else {
return false;
}
}
public static function t($str='',$params=array(),$dic='message') {
return Yii::t("MessageModule.".$dic, $str, $params);
}
public function getCountUnreadedMessages($userId) {
return Message::model()->getCountUnreaded($userId);
}
}
然而,當我嘗試運行它,我發現上的問題「Method User :: getFullName not defined」
請幫忙... 謝謝...
可能有些文件不包含在自動加載, – tinybyte 2015-02-10 14:05:05
將'getFullName'方法添加到''用戶'模型。 – 2015-02-10 14:12:05